Linux training tutorial Git use under linux


    *Initialize the git warehouse, use the gitinit command

  *Add files to the git warehouse in two steps:

  1. Use git add filename; it can be used multiple times, adding multiple files to the staging area

2. Use git commit -m "description"; Complete the submission to the branch

Brothers linux training

tutorial Git use under

linux   * To view the status of the workspace, use the git status command; if there is a prompt, you can use git diff filename to view the modified content   *HEAD points to the current version, HEAD^ indicates the previous version, HEAD^^ Previous version...HEAD~100 points to the 100th version before.   * Rollback version: use git log to view the commit history; use gitlog --pretty=oneline to simplify the display;   use git reset --hardcommit_id to roll back to the version with the version number of commit_id   * After the rollback version, if you want to see and change it back, you can use git reflog View historical commands, find out the version number you want to change back, and then use git resethard commit_id to return.   *Note: git tracks and manages modifications, not files. If a file is modified and added, it is modified again. If it is submitted without adding it again, only the first modification will be submitted.   *Undo modification:   1. If the file is still in the workspace, that is, there is no add or commit, use gitcheckout -- filename to restore to the server version;


















  2. If it has been added to the staging area, first use git reset HEAD filename to retrieve the workspace from the staging area, and then operate according to 1;

  3. If it has been submitted to the repository, follow the version rollback method Just modify it;

  4. If you have pushed to the remote warehouse, you will be in trouble

  *Delete use the following commands:

  1. gitrm filename delete from the workspace

  2. gitcommit -m "Description" Update the files in the branch to delete

  the files in the workspace After deletion, you can use gitcheckout -- filename to get back from the branch, but you can only restore the file to the latest version, and the changes after the last commit cannot be restored.

  *Branch:

  1. Create a branch

  git checkout -b branchname Create and switch to the new partition, which is equivalent to the following two commands:

  git branch branchname Create a branch

  git checkout branchname Switch to the partition

  2. View the currently pointed branch: git branch will list For all branches, there is an additional * before the branch currently pointed to.

  3. The switch branch is git checkout branchname

  4. Merge branch: git merge branchname merge branchname into the current branch

  5. Delete branch: git branch -d branchname delete branchname branch

  Note: creating, merging, and deleting branches is very fast, git encourages the use of branches to complete a certain task, and deleting branches after merging has the same effect as working directly on the master branch, but the process is safer; these are faster because In these processes, we just modify the pointer to the branch. For example, to create a branch is to create a pointer to the branch, and then modify HEAD to point to the pointer; that is, HEAD points to the branch, and the branch is the commit.

  *Conflict resolution: When git cannot automatically merge branches, you must first resolve the conflict; after resolving the conflict, submit it, and the merge is completed.

  Use git log --graph to view the branch merge graph.

  *Save the work site git stash After saving, you can do other work without affecting the last modification.

  Restoring work site: 1. When git stash apply restores, it does not delete the content in stash.

  2. When gitstash pop restores, it will delete the content in stash

  * Remote library information production Use git remote (-v) plus -v to display more detailed information

  * Branch push to remote library: push all local commits to remote library

  git push origin (remote library name) master (branch to be pushed )

  *Grab the branch: git pull ; git clone

  *Collaboration mode:

  1. Use git push origin branchname to push your own changes

  2. If the push fails because the remote branch is newer than the local one, first use git pull to merge

  3. If there is a conflict in the merge , resolve the conflict, submit

  4 locally, and push again

  Note: If "no tracking information" is displayed when merging with git pull, it means that the local branch does not have a link relationship with the remote branch, use the following command to establish a relationship: git branch --set -upstream branch origin/branchname

  *Create a local branch corresponding to the remote branch Branch: git branch -b branchname origin/branchname The names of the local and remote branches should be the same

  *Create a tag

  1, tag git tag name The default tag is tagged on the latest commit, if you want to tag it on other versions, find the commit_id that is 2. Display tags: git log -pretty

  =oneline --abbrev -commit

  git tag tag_name commit_id

  3. View tags: git tag Display all tags

  4. View tag information: git show tag_name

  5. Create tags with descriptions: git tag -a tag_name -m "information";-a indicates the tag name, -m specifies the description text

  *Operate the tag: git tag -d tag_name Delete the tag

  Push the tag to the remote library: git push origintag_name

  Push all tags to the remote library at once: git pushorigin --tag


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326444110&siteId=291194637