Undoing
Keep changes staged
git reset --soft HEAD~1
Undoes the commit but keeps changes staged. Moves HEAD back one commit and stages the changes; see git-reset.
Keep changes unstaged
git reset --mixed HEAD~1
Undoes the commit and unstages changes. Moves HEAD back but keeps the working files; see git-reset.
Discard changes
git reset --hard HEAD~1
Discards the commit and its changes. Deletes them from the working tree; only use it for unpublished work. See git-reset.
Undo a pushed commit
git revert HEAD
Reverses a pushed commit safely. Creates a new commit that reverses the last one, keeping shared history intact. See git-revert.
Related links
- git-reset manual (git-scm.com)
- git-revert manual (git-scm.com)
0 Comments for this cheatsheet. Write yours!