Git revert vs reset — one question decides
Has anyone else pulled the commit? Yes → git revert <sha>. No → git reset, any mode. --soft keeps edits staged, --mixed (default) unstaged, --hard deletes them — the only shredder.
Git revert vs reset comes down to one question: has anyone else pulled the commit? Yes → git revert <sha>. No → git reset, any mode. Revert grows history with a compensating commit; reset shrinks it.
question decides: has anyone else pulled the commit? If yes, reset is off the table — a plain git pull must still merge cleanly for everyone.
Has anyone else pulled the commit?
Two minutes in a throwaway repo: 2 commits, 3 after the revert, 1 after the reset. That asymmetry is the whole answer.
1a2b3c4 (HEAD -> main) Revert "two" ← the cancellation5d6e7f8 two ← still in the log9f8e7d6 one# after git reset --hard HEAD~1:9f8e7d6 one ← "two" is unreachable
| Mode | Branch pointer | Staging area | Working tree | Your edits |
|---|---|---|---|---|
--soft | moves back | kept staged | untouched | fully kept |
--mixed (default) | moves back | unstaged | untouched | kept, unstaged |
--hard | moves back | reset | reset | deleted |
- Commit is public (pushed, others pulled) →
git revert <sha>. - Local-only, want to redo it →
git reset --softor--mixedand recommit. - Local-only, want it gone with the uncommitted mess →
git reset --hard, after one honest look at what else the working tree holds. - One file got mangled →
git restore <file>and leave the branch alone.
restore fixes files, reset moves branches, revert undoes published commits.
two sharp edges, and where restore fits
git revert -m 1 <sha> # merge has two parents
git restore file # discard working-tree edits
git restore --staged file # unstage
git reflog # HEAD@{n} walks back a reset, ~90 days Reverting a merge needs -m 1, else git refuses; re-merging that branch later looks already-applied, so re-landing means reverting the revert. Revert isn't a time machine — it undoes one commit's diff, and later commits touching the same lines can conflict. git restore and git switch arrived in git 2.23; the old git checkout -- file forms still work everywhere.
- tested on: git 2.4x · Linux · macOS · Windows
- demo: throwaway repo at /tmp/revert-vs-reset · 2 commits → 3 after revert → 1 after reset
- mode behaviour · merge-revert -m 1 · reflog ~90 days — git's documented behaviour
- first published 2026-09-15 · record refreshed 2026-10-10