undo the last git commit
Take back a commit, keep its changes or not, fix its message, or undo one already pushed.
Steps
-
git reset --soft HEAD~1undo it, keeping its changes staged
-
git reset HEAD~1undo it, keeping the changes, unstaged
-
git commit --amendchange its message, or add what you forgot (git add first)
-
git revert HEADalready pushed: a new commit that undoes it
-
git reflogevery place HEAD was: find a commit you lost
Notes
- Do not reset or amend commits others already pulled; revert them.
Commands used
git
Each has a page in lore: lore git opens it.