What is the difference between git reset, git revert and git restore?

Git & SDLC Undoing Changes Intermediate 1–2 Yrs2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

git revert <sha> creates a new commit that undoes an earlier one — safe for shared history. git reset moves the branch pointer back (and optionally the index/working dir with --soft/--mixed/--hard) — rewrites history, only for local commits. git restore discards changes in files (working dir or index) without touching commits.

git revert makes a brand-new commit that's the inverse of a previous one, so it's what I use to undo something that's already on the shared branch — it doesn't rewrite anyone's history. git reset moves my branch pointer backwards; with --soft it keeps my changes staged, --mixed unstages them, --hard throws them away entirely, and because it rewrites history I only use it on local unpushed commits. git restore is the newer command for file-level operations — unstaging a file or discarding uncommitted edits — without touching commits at all.

  • reset --soft — move HEAD, keep everything staged (redo the commit). --mixed (default) — unstage too. --hard — also discard working changes (dangerous).
  • revert is the right tool to undo something already pushed — it doesn't rewrite what others have.
  • restore --staged file unstages; restore file throws away working edits; restore --source=<sha> file restores an old version.
  • reset --hard loss is often recoverable via git reflog if you act quickly.