2020年12月7日星期一

Introduction of git rollback commands.

git status and rollback commands:

1. editing.  a new source file editing, without any git operation.

git checkout -- a.txt   # rollback  a.txt 
git checkout -- .       #  rollback all files.

2. stage.   after git add

git reset HEAD a.txt    # rollback  a.txt 
git reset HEAD .  #  rollback all files.
      

3. committed.   after git commit

git log # get the commit id you want to rollback 
git reset --hard <commit_id_youget_above> 
# or 
git reset --hard HEAD^  # rollback to last commited and added 
git reset --soft HEAD^  # rollback commit only, ignore added
# or 

git reset HEAD^  # rollback to git add .



4. pushed.   after git push

git log # get the commit id you want to rollback 
git reset --hard <commit_id_youget_above> 

# force push for deleting the remote sources after 
commit_id_youget_above
git push origin HEAD --force

5. git branch -D branchname

没有评论: