Undo commits with git reset (soft, mixed, and hard)

domain: git-scm.com/git · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Decide how much history to undo and which mode matches your need.
  2. Soft reset — move HEAD but keep working tree and index: git reset --soft HEAD~1 or git reset --soft <commit>. Combine with git commit to redo the commit with different content.
  3. Mixed reset (default) — move HEAD and reset the index but leave the working tree: git reset HEAD~1. Unstages changes that were staged.
  4. Hard reset — move HEAD, reset the index, and overwrite the working tree to match: git reset --hard HEAD~3 (discards the last 3 commits' changes).
  5. Unstage a file without touching working tree: git reset <pathspec> (equivalent to git restore --staged <pathspec>).
  6. To undo a merge or pull, git pull/merge leaves the original tip in ORIG_HEAD; run git reset --hard ORIG_HEAD to undo.

Known gotchas

Related routes

Recover commits lost to a reset, rebase, or branch deletion using git reflog
git-scm.com · 6 steps · unrated
Safely undo or roll back changes: discard working-tree edits, unstage files, undo the last commit(s), or recover a commit that looks lost
git-scm.com/docs/git-restore · 8 steps · unrated
Undo a pushed commit by creating an inverse commit with git revert
git-scm.com · 8 steps · unrated

Give your agent this knowledge — and 18,300+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans