Liao Xuefeng's git notes

I haven't used git for a long time, let's review:
Liao Xuefeng's Git tutorial

I have excerpted all the important points in the original text, it is enough to master the following commands

  • Roll back the current version to the previous version
    git reset --hard HEAD^
    git reset --hard 3628164
  • View your every command
    git reflog
  • Revoke all the modifications of the readme.txt file in the workspace,
    git checkout-readme.txt
    is to make this file return to the state of the last git commit or git add.
  • Unstage the modification of the temporary storage area (unstage) and put it back into the workspace
    git reset HEAD readme.txt
  • Delete the file
    git rm test.txt from the repository
  • Create the dev branch, and then switch to the dev branch
    git checkout -b dev
    git checkout command plus the -b parameter means to create and switch, which is equivalent to the following two commands: $ git branch dev $ git checkout dev
  • View current branch
    git branch
  • Switch back to the master branch
    git checkout master
  • Merge the work results of the dev branch to the master branch
    git merge dev The
    git merge command is used to merge the specified branch to the current branch.
  • Delete the dev branch
    git branch -d dev
  • "Store" the current work site
    git stash
  • Where is the job site saved?
    git stash list
  • You need to restore the work site.
    One is to restore with git stash apply, but after the restoration, the stash content is not deleted, you need to delete it with git stash drop; the other way is to use git stash pop, and the stash content is also deleted while restoring Up
  • Restore the specified stash
    git stash apply stash@{0}
  • View the information of the remote library
    git remote
    Use git remote -v to display more detailed information:
  • When pushing the branch
    git push origin master
    , you must specify the local branch, so that Git will push the branch to the remote branch corresponding to the remote library:
  • Multi-person collaborative work mode
    1. First, you can try to push your own changes with git push origin branch-name;
    2. If the push fails, because the remote branch is newer than your local, you need to use git pull to try to merge;
    3. If there is a conflict in the merge, resolve the conflict and submit it locally;
    4. After there is no conflict or the conflict is resolved, push with git push origin branch-name again to succeed! If git pull prompts "no tracking information", it means local The link relationship between the branch and the remote branch is not created, use the command git branch --set-upstream branch-name origin/branch-name.
  • Make a new tag
    First, switch to the branch that needs to be tagged, then git tag v1.0
  • View all tags
    git tag
  • Tag specific commits
    git tag v0.9 6224937
  • View label information
    git show v0.9
  • Create a tag with instructions
    Use -a to specify the tag name, -m to specify the description text:
    $ git tag -a v0.1 -m "version 0.1 released" 3628164
  • Remove tag
    git tag -d v0.1
  • Push a tag to the remote,
    git push origin v1.0
  • Push all local tags that have not yet been pushed to the remote at one time
    git push origin --tags
  • Delete remote tag
    First delete from local: $ git tag -d v0.9
    remote delete. The delete command is also push, but the format is as follows: $ git push origin :refs/tags/v0.9

Guess you like

Origin blog.csdn.net/u011703187/article/details/90180046