Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

Git Revert vs Reset: Which One Saves Your History?

Revert adds a commit that undoes an earlier change and is safe for shared branches. Reset moves the branch pointer and suits local, unpublished commits. Here is how the reset modes differ and how to avoid losing work.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use git revert when a commit may already be on a shared remote or other people may have built on it. Revert adds a new commit that reverses the earlier change, so the original commit stays in the branch history. Use git reset when you are cleaning up local commits that nobody else has seen. Reset moves the current branch pointer backward, which rewrites the branch’s recent history. The reset mode then decides what happens to your staged changes and working files, and --hard is the mode that can destroy work.

What each command does to history

git revert: adds a corrective commit

git revert <commit> applies the inverse of a commit’s patch and, by default, records the result as a new commit. The bad commit is still in the log, and the branch moves forward with the correction. Because no existing commit is altered, collaborators who already fetched the original commit can pull the revert without any special handling. This is the reason revert is the safe choice for shared branches.

As an Amazon Associate I earn from qualifying purchases.

git reset: moves the branch pointer

git reset [mode] <commit> sets the current branch’s HEAD to the target commit. It does not create a reversing commit. Depending on the mode, it also changes the index (the staging area) and the files in your working tree. The commits that were removed from the branch are no longer reachable from it, which is exactly what makes reset useful for tidying up local work and exactly what makes it risky once those commits have been pushed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reset modes: what each one changes

Think of Git as three layers: the branch pointer (HEAD), the index, and the working tree. The mode controls how far a reset reaches into the lower two layers.

Command Branch tip (HEAD) Index (staging area) Working tree files Typical use
git reset --soft <target> Moves to target Unchanged Unchanged Undo commits but keep every change staged, ready to recommit
git reset --mixed <target> (default when no mode is given) Moves to target Set to match target Unchanged Undo commits and leave the changes in the working tree, unstaged
git reset --hard <target> Moves to target Set to match target Overwritten to match target Discard tracked changes and commits; can destroy uncommitted work

The official git-reset documentation says that --hard overwrites files and directories with their versions in the target and may also overwrite untracked files. Check git status and save anything you want before running it.

Which command to use in common situations

Situation Command What to watch for
Undo a commit that is already pushed or shared git revert <commit> Adds a new commit; no history is replaced for collaborators
Undo your last local commit and keep its changes staged git reset --soft HEAD~1 Changes stay in the index, so the next commit contains them
Undo your last local commit and keep its changes unstaged git reset --mixed HEAD~1 Files keep your edits, but you must stage them again
Undo your last local commit and throw away its tracked changes git reset --hard HEAD~1 Removes the commit and overwrites matching working files
Unstage one file but keep your edits git restore --staged <path> Touches only the index; working-tree edits remain
Undo edits to a file that has not been committed git restore <path> or git restore --source=<commit> <path> Not a commit undo; choose the source version deliberately
Revert a merge commit git revert -m <parent-number> <merge> The parent number selects the mainline to keep; check the resulting patch

Undoing your last local commit

This procedure applies only to commits that exist solely on your machine. If the commit has been pushed, go to the revert section below.

  1. Run git log --oneline -5 and confirm the commit at the top is the one you want to remove.
  2. Run git status. Note any uncommitted edits, because they will be affected by the reset mode you choose.
  3. Choose the mode. For most people who want to rewrite the commit and keep the code, run git reset --soft HEAD~1. Use --mixed if you want to restage selectively.
  4. Run git status again. With --soft, the former commit’s changes should appear under “Changes to be committed.”
  5. Commit again with git commit, or adjust the files first and then commit.

Pushing a branch whose history you have rewritten requires a force update, so use git push --force-with-lease rather than --force, and only after the people sharing the branch know about the change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Unstaging a file without losing edits

git restore --staged <path> copies the version of that file from HEAD into the index, so the file is no longer staged. Your working-tree copy is untouched. The older form git reset <path> does the same thing for this purpose, and the official reset documentation describes it as the equivalent of the modern command. Neither form moves the branch pointer.

Undoing edits to an uncommitted file is a separate task. git restore <path> takes the version from the index, which discards your unstaged edits in that file. git restore --source=<commit> <path> takes the file from a specific commit. Confirm the source before you run either one, because the change cannot be reversed from Git’s history once you overwrite the file.

Undoing a commit that has been pushed

Revert is the right tool here. The steps are:

  1. Run git revert <commit>. Git opens your editor for the new commit message; the default message names the reverted commit.
  2. Review the change with git show HEAD to confirm it removes what you intended.
  3. Push normally with git push. No force update is needed.

Git’s revert command requires a clean working tree by default. Commit or stash your uncommitted changes first. If the revert conflicts, Git stops and waits for you. Resolve the conflicts, stage the files, and run git revert --continue. To abandon the operation, run git revert --abort. git revert --skip drops the current commit from the sequence and is rarely needed for a single revert.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reverting a merge commit

A merge commit has more than one parent, so Git cannot know which side should be treated as the baseline. The -m option names that baseline by parent number. Parent 1 is the branch you were on when you ran the merge, which is the usual choice, so git revert -m 1 <merge> removes the changes that came in from the merged branch. Inspect the new commit with git show before pushing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A reverted merge has a side effect. Git now treats the merged branch’s changes as already applied and may skip them if you merge that branch again later. Reverting the revert is the usual recovery path, and it is worth discussing with your team before you do it.

Before you run reset –hard

  • Run git status and confirm which files would be overwritten.
  • Stash changes you want to keep, including untracked files, with git stash push -u.
  • Create a branch as a bookmark with git branch backup/before-reset, so the current commits stay reachable after the reset.
  • Run the reset only after the checks above pass.

Recovering after a bad reset

Git records where HEAD has been in the reflog. Run git reflog to find the commit hash from before the reset, then create a branch at that hash with git branch recovered-work <hash>. Starting with a branch is safer than resetting straight back, because it does not overwrite anything else. After a reset, Git also stores the previous tip in ORIG_HEAD, which is useful for a quick undo of the most recent reset.

The reflog and ORIG_HEAD cover committed states only. Uncommitted edits that a --hard reset or a restore overwrote are not stored in Git’s history and generally cannot be recovered through these tools. That is why the backup steps above come before the destructive command, not after it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.