Skip to main content
git revert vs reset vs restore: Which to Use

git revert vs reset vs restore: Which to Use

KU
· Founder & Chief Editor
• 8 min read•Updated •69 views

Three Git commands that all "undo" things, and picking the wrong one on a shared branch is how you ruin a teammate's afternoon. Here's how to keep them straight.

Key takeaways

  • Use git revert for commits that are already pushed, because it adds a new commit that undoes the old one without rewriting history.
  • Use git reset to reshape local commits you have not pushed yet.
  • Use git restore to discard or unstage file changes; it never touches commits or moves your branch.

Use git revert for anything already pushed: it adds a new commit that cancels the bad one and leaves shared history alone. Use git reset to move your branch pointer back over local, unpushed commits. Use git restore to throw away or unstage file changes. The first question is always "has this left my machine?"

Verified against

Git 2.56.0 (latest release listed on git-scm.com), against the git-scm.com reference pages for git-revert, git-reset, git-restore and git-reflog. Checked October 2026.

The three commands sound like synonyms. They are not. Reach for the wrong one and you either lose work or rewrite history that other people have already pulled. Both mistakes are common, so get the distinctions clean before you type anything with --hard in it.

The short version: revert undoes a commit by making a new commit. reset moves your branch pointer backwards. restore throws away changes in files. That's the whole map. The rest is knowing which situation you're in.

The mental model: HEAD, index, working tree

Every one of these commands moves content between three places, and if you hold that picture in your head the flags stop being cryptic.

  • HEAD: the commit your branch currently points at. The last thing you committed.
  • Index (also called the staging area): what goes into your next commit. git add puts things here.
  • Working tree: the actual files on disk you're editing right now.

Work flows from working tree to index to HEAD when you save. These three commands move it the other direction, and they each stop at a different layer. Keep that in mind and the flags below read like plain English.

git revert: undo safely, in public

git revert <commit> creates a new commit that is the inverse of the one you name. If a commit added a line, the revert removes it. Nothing gets erased, the history stays intact, and everyone who already pulled the bad commit just gets a follow-up commit that cancels it out.

Bash
$ git revert a1b2c3d                       # undo one commit, opens an editor for the message
$ git revert HEAD                          # undo the most recent commit
$ git revert --no-commit a1b2c3d b4c5d6e   # stage several undos, commit them together

This is the command for anything already pushed. It's non-destructive and it plays fair with your teammates. The only downside people complain about is the extra commit in the log, which is a strange thing to be upset about when the alternative is rewriting shared history. One caveat from the docs: reverting a merge commit needs -m 1 (or -m 2) to say which parent is the mainline, and it does not undo the merge's history, only its changes.

git reset: move the pointer, quietly

git reset drags your branch pointer to a different commit. Where it stops among those three layers depends on the flag:

Bash
$ git reset --soft HEAD~1     # undo commit, keep changes staged in the index
$ git reset --mixed HEAD~1    # undo commit, keep changes in working tree (the default)
$ git reset --hard HEAD~1     # undo commit, discard changes entirely

--soft is our go-to for "I committed too early." It rewinds the commit but leaves everything staged, ready to recommit properly. --mixed, the default, unstages too, so you're back to edited-but-not-added. --hard also wipes the working tree, which is exactly as final as it sounds. For the narrow "undo my last commit" case, undoing the last Git commit walks through each variant.

Because reset rewrites where the branch points, it's a local-only tool. Run it on commits you've pushed and your branch diverges from the remote, so your next push gets rejected (the error in fixing a rejected git push) and the "fix" is a force-push that stomps on whatever your colleagues built on top. Don't. Reset is for cleaning up your own laundry before anyone sees it.

git restore: for files, not commits

git restore is the newer command carved out of the overloaded git checkout, and it only deals with file contents. No commits, no branch pointers.

Bash
$ git restore config.yml              # discard working-tree edits to one file
$ git restore .                       # discard all unstaged edits (careful)
$ git restore --staged config.yml     # unstage, keeping the edits
$ git restore --source=HEAD~2 app.py  # pull a file's older version back

If you've ever fumbled git checkout -- file and worried you were about to switch branches instead, restore is the fix. It does one job. Discarding working-tree changes and unstaging files used to share a command with branch switching, which confused everyone; now they're split (switch handles branches, restore handles files).

The decision table

SituationCommandRewrites history?Safe after push?Can lose work?
Bad commit already pushed or on a shared branchgit revertNoYesNo
Local commits you haven't pushed, want to reshapegit reset --soft or --mixedYesNoNo
Local commits you want gone, changes and allgit reset --hardYesNoYes (reflog may save you)
Uncommitted file edits you want gonegit restoreNoYesYes, uncommitted edits are unrecoverable
Staged something by mistakegit restore --stagedNoYesNo
Need an old version of one filegit restore --source=<commit>NoYesOverwrites the current file

Read it top to bottom. The first question is always "is it pushed?" If yes, you're in revert territory and the conversation is over. If it's local and about commits, reset. If it's about files rather than commits, restore.

The reflog is your seatbelt

The part that makes reset --hard survivable on your own branch: Git rarely deletes commits immediately. It just stops pointing at them. git reflog shows every position HEAD has held, including the commit you thought you nuked.

Bash
$ git reflog                  # find the commit you lost, note its hash
$ git reset --hard a1b2c3d    # or: git switch -c rescue a1b2c3d

We've recovered from a panicked --hard more than once this way. It's not infinite. Per the git-reflog docs, entries for commits no longer reachable from a branch expire after gc.reflogExpireUnreachable, which defaults to 30 days, and other entries after gc.reflogExpire, 90 days by default. Knowing reflog exists is the difference between "oh no" and "give me thirty seconds." What reflog cannot save is uncommitted work: git restore and reset --hard on edits you never committed are gone for good.

Questions people ask

What is the difference between git revert and git reset?

git revert creates a new commit that applies the inverse of an earlier one, so history only grows and anyone who already pulled is unaffected. git reset moves the branch pointer to an older commit, effectively removing later commits from the branch. That rewrites history, so it is safe only on commits that have never been pushed. Use revert on shared branches, reset on private ones.

Can I undo a git reset --hard?

Usually, if the work was committed. Run git reflog, find the hash HEAD pointed at before the reset, and run git reset --hard <hash> or create a branch from it. Unreachable reflog entries expire after 30 days by default. Changes that were never committed or staged are not recorded anywhere, so a hard reset over uncommitted edits cannot be undone.

Is git restore the same as git checkout?

For files, yes in effect. git restore <file> does what git checkout -- <file> did: it overwrites working-tree edits with the version from the index or a chosen commit. The difference is scope. git checkout also switches branches, which made typos dangerous, while git restore only touches file contents and git switch handles branches.

The call we'd make

Default to revert the instant anything has left your machine. It costs you one extra commit and buys you a history nobody has to untangle later. Save reset for tidying local work before you push, lean on --soft far more than you think, and treat reset --hard on a shared branch as something you simply do not do. Use restore for files, because that's what it's for and it says what it means. And whenever the panic rises, run git status and git reflog first. If you want the broader map of Git messing with your day, our Git troubleshooting guide covers the rest.

Sources

Explore topics:DevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). git revert vs reset vs restore: Which to Use. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/git-revert-vs-reset

Markdown

[git revert vs reset vs restore: Which to Use](https://www.devopsness.com/blog/git-revert-vs-reset) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.