I always forgot which git reset mode deletes work. So I ran all three in a scratch repo (git 2.34.1) with the same setup: one commit one containing f.txt = "one", then a second commit that adds the line "two".
For each mode I ran git reset --<mode> HEAD~1, then git log --oneline, git status -s and cat f.txt.
--soft
log: f2b3ee7 one status: M f.txt file: one / two The commit is gone, the change is still in the file and still staged (M in the first column). Use this to redo a commit message or to squash commits.
--mixed (the default)
log: f2b3ee7 one status: M f.txt file: one / two Same file content, but the change is no longer staged (M in the second column). You keep all your work and choose what to git add again.
--hard
log: f2b3ee7 one status: (nothing) file: one The commit is gone and the line "two" is gone from the file too. This is the only mode that throws away uncommitted work. If you did it by mistake, git reflog still lists the old commit for a while, and git reset --hard <that hash> brings it back.
Quick rule
- Want the commit undone, work kept and staged:
--soft. - Want the commit undone, work kept, nothing staged:
--mixed. - Want everything back to how the old commit looked:
--hard, and checkgit statusfirst.
I keep a longer tested walkthrough (undo the last commit, with the common mistakes) on my small guide site: https://kairos-2z6s.onrender.com/res/undo-last-git-commit-en
Disclosure: my guide site shows one ad banner, and a sponsored page appears before the full kit if you use its Continue link. This article stands on its own.
