git reset vs git revert

Compare reset --hard moving the branch pointer back (abandoning commits) with revert creating an undo commit — animated on the commit graph.

Scenario

Speed
c1initc2wip 1c3wip 2c4wip 3c5Revert "wip 3"HEADmain

Branch state

mainc2◀ HEAD

Current step 6/6

$ git reset --hard HEAD~3

reset --hard moves the branch pointer back. Commits no branch can reach are abandoned. Local-only — never reset commits others have pulled.

$ git log --oneline --all

c2 (HEAD -> main) wip 1

c1 init

File content (at HEAD) — app.js @ main

1initc1
2wip1c2
−wip2c3 removed
commit abandoned commitHEAD HEAD

Circles are commits; dimmed circles were abandoned by rebase/reset. A prime (c3') means same content, rewritten hash. In sandbox mode, run commands yourself with the buttons.

reset and revert both undo work but in opposite ways. reset --hard moves the branch pointer back so later commits vanish from history, while revert adds a new commit that undoes the target — history is preserved.

Commits abandoned by reset become unreachable garbage: reflog can resurrect them for a while, but eventually they're collected. --hard also discards working-tree changes, so use it carefully.

For commits already pushed, revert is the only safe option. Resetting published commits forces a force-push that breaks your teammates' histories; revert just adds a commit, so it shares with a normal push. Git Branch Simulator

Frequently asked questions

What's the fundamental difference between reset and revert?
reset moves the pointer back and erases history; revert appends a new undo commit. Erased commits become unreachable and are abandoned.
How do I undo a commit I've already pushed?
Use revert. Resetting published work requires force-push, which collides with everyone else's history. Revert shares cleanly via a normal push.
What do --soft, --mixed and --hard do?
--soft moves the pointer keeping changes staged; --mixed (default) unstages but keeps files; --hard resets files too, discarding all changes.

Other scenarios

Related tools