1 , undo before commit Undo not added to the staging area (before add) git status git checkout . Undo added to the staging area (after add) git reset HEAD : roll back the files that have been added to the staging area to the state that was not added to the staging area, and then git checkout to return to the most original state 2 , Cancellation after commit ( git add . git commit -m "commit" git push origin brandname ) Undo after a series of operations I do not want this operation to take effect git revert commitId (commit id) git push origin brandname This operation will undo the last push On this branch, a revert commit record will be generated revert is negative and positive, what does it mean, that is, when reverting for the first time, the last push command will be invalid, and after reverting again, it will go back to the previous state. Introduce in detail For example, I operate a file UserController.java Change userName to username after a series of git operations git add . git commit -m "commit" git push orgin After that, do git revert commitId again Then do git push origin branchname userName or userName, If I revert again, git revert git push origin branchname Change userName to username. Summarized as: git revert takes effect when it is odd, and fails when it is even 3 , git rollback: Roll back git to a commit operation, and all operations before the commitId will be invalid (this method is not recommended and has risks), git reset --hard commitId git push origin branchname --force (force overwrite)
is not recommended because it is irreversible