[git] common commands


Git common commands

View submission history

git log  
git log --pretty=oneline -n
git log --pretty=format:"%h %s" --graph

discard changes

  1. When the file is not put into the staging area

    git checkout -- <filepath>
    git checkout -- .    
  2. The file has been put into the staging area

     git reset HEAD <filepath>
     git reset HEAD .    
  3. The file has been committed

    git reset --hard <commitid>
    git reset --hard HEAD^

New branch

git branch <name>
git checkout <name>

#Or create and switch:
git checkout -b <name>

Variable base

#Assume that the current working branch is Branch2, and submit the code based on branch1
git rebase branch1
git checkout branch1
git merge branch2
git push