The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →To undo your latest commit and keep its changes staged, run git reset --soft HEAD~1. To undo it and keep the changes in your files but unstaged, run git reset HEAD~1. Both commands leave your files alone. The one command to avoid when you want to keep work is git reset --hard.
Check the commit before you reset
Both reset commands move the current branch backward by one commit, so run these checks first:
As an Amazon Associate I earn from qualifying purchases.
- Run
git statusto see whether you have staged, unstaged, or untracked changes you also need to keep. - Run
git log --oneline -3to confirm that the commit you want to undo is the tip of the current branch (the top line). - Confirm that the commit has not been pushed to a shared branch. If it has, skip to the revert section.
HEAD~1 means the parent of the current commit. If the commit you want to undo is a merge commit, HEAD~1 points to its first parent. Check git log --graph --oneline if the history is complicated. If the tip is the repository’s first commit, it has no parent, and HEAD~1 will fail.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Which command keeps what
The three reset modes differ only in how far they reach beyond the branch pointer. The table below summarizes the Git project’s git-reset documentation (version 2.53.0 page) alongside the related commands.
#1 Best Overall
| Command | Moves branch tip | Index (staged changes) | Working tree files | Best use |
|---|---|---|---|---|
git reset --soft HEAD~1 |
Back one commit | Unchanged, so the commit’s changes stay staged | Unchanged | Recommit the same work with a different message or a different grouping of files |
git reset HEAD~1 (default --mixed) |
Back one commit | Reset to the new tip, so the changes become unstaged | Unchanged | Reconsider what to stage before committing again |
git reset --hard HEAD~1 |
Back one commit | Reset to the target commit | Reset to the target commit, which discards uncommitted edits to tracked files | Discarding the commit and its work. Not a preservation command |
git commit --amend |
Replaced by a new tip commit | Staged changes are folded into the new commit | Unchanged | Fixing the message or adding a missed file to the latest commit |
git revert HEAD |
Advances by a new commit that reverses the change | Changed by the reversal | Changed by the reversal | Undoing a commit that others may already have |
The core distinction is between --soft and the default mode. Both move the branch back, but --soft keeps the index as it was, while the default mode resets the index to match the new tip.
Keep the changes staged with –soft
Use this when the commit was almost right and you want to change the commit message or regroup the files before committing again.
Rank #2
- Used Book in Good Condition
- Run
git reset --soft HEAD~1. - Run
git status. The files from the undone commit should appear under “Changes to be committed.” - Run
git diff --cachedto review exactly what will go into the next commit. - Run
git commitwith a new message, or rungit reset HEAD <file>to unstage specific files before committing.
If you already had staged changes before the reset, they will be combined with the undone commit’s changes in the next commit. Check step 3 to be sure that is what you want.
Free tools Windows power users keep installed
One-click scans. No signup required.
Keep the changes unstaged with the default mode
Use git reset HEAD~1 when you want to revisit the work and decide what to stage. The branch moves back and the index is reset, but the files keep their content.
Rank #3
- Run
git reset HEAD~1. - Run
git status. Modified files appear under “Changes not staged for commit.” - Files that the undone commit added appear under “Untracked files” because the index no longer contains them.
- Stage what you want with
git addand commit again, or usegit add -pto stage individual hunks.
If the commit is already shared, use revert
Once a commit has been pushed and others may have based work on it, rewriting the branch with a reset can cause problems for collaborators. The Git project’s git-commit documentation makes the point directly: you should understand the implications of rewriting history if you amend a commit that has already been published. The same caution applies to resets on shared branches.
git revert HEAD records a new commit that reverses the latest commit’s changes. The existing history stays intact. The git-revert documentation describes this as recording new commits that undo the changes the earlier patches introduce.
Rank #4
- Run
git status. Revert requires a clean working tree, so commit or stash anything pending first. For example,git stash push -ustashes tracked and untracked changes. - Run
git revert HEAD. Git opens your editor with a default message for the reversing commit. Usegit revert --no-edit HEADto accept that message without opening the editor. - Run
git log --oneline -2to confirm the new reversing commit is on top of the original. - Push normally. No force push is needed.
Commands to avoid for this goal
git reset --hard HEAD~1 resets the index and working tree to the target commit. Uncommitted edits to tracked files are discarded. The reset documentation also warns that it can overwrite untracked files. Avoid it unless you have intentionally decided to throw the work away.
git commit --amend is for correcting the latest commit, not for removing it. Use it for a message fix or a forgotten file on a local commit that has not been shared.
Best Value
Recover if you reset by mistake
The reset documentation states that reset saves the previous branch tip to ORIG_HEAD. If you realize right away that you did not mean to reset, running git reset --soft ORIG_HEAD returns the branch to the commit you had before. The Git documentation describes ORIG_HEAD as a reference for the previous tip, but it is not a guarantee that works in every situation, because later operations can overwrite it.
For older states, git reflog lists where HEAD has pointed recently. Find the hash of the commit you want, then run git reset --soft <hash> to restore it. The Pro Git book’s Reset Demystified section explains how these reset modes map onto the index and working tree.
Troubleshooting
- HEAD~1 fails: the tip is the first commit in the repository, which has no parent. Use
git update-ref -d HEADonly if you intend to start the branch history over, or create a new commit on top instead. - The staged files are not what you expected: run
git diff --cachedandgit diffto see the index and the working tree separately. - Revert refuses to run: the working tree is not clean. Commit or stash your changes, then run revert again.
- You pushed and then reset: do not force push without coordinating with collaborators. Use
git revertfor the fix, or agree on a force push with everyone who has the branch.
The official reference pages are the git-reset documentation (version 2.53.0), the git-commit documentation, the git-revert documentation, and the Git user manual’s “Fixing mistakes” section. Behavior details can vary slightly between Git versions, so check git --version and the matching documentation if a command behaves differently on your machine.
Quick Recap
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.




