Git undo commit operation command git reset--hard head^
First, new three files, Demo1,demo2,demo3
Second, git add command to staging area, git reset HEAD demo1 is the file submitted to staging area revocation.
, executing git reset HEAD demo1 will remove demo1 from staging area and is now untracked.
Third, Git commit commits the local repository
, Git commit commits the DEMO2,DEMO3 to the local repository.
Four, now want to undo the previous commit, you can use the git reset--hard head^ command
In the third step, commit demo2, then commit DEMO3, so now the head is the commit value of DEMO3.
(Head is pointing to the latest commit, last Commit is head^, previous is head^^, can also be written as head~2, and so on)
So git reset--hard HEAD is to undo the latest commit Demo3, Undo is very thorough and local files will be deleted.
Now run the LS command and you will find: The Demo3 file is no longer available.
Git Undo Commit Considerations