How do I undo 'git reset'?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
You can often undo git reset, but the recovery method depends on which reset mode you used and whether the lost state still exists in the reflog. In most cases, the first command to reach for is git reflog, because it records where HEAD pointed before the reset.
The short version is this: if the reset moved commits around, reflog can usually bring them back. If git reset --hard destroyed uncommitted working-tree changes, recovery is much less certain.
Start with git reflog
git reflog shows recent HEAD movements, including resets:
You will see entries like:
If you want to undo the reset and return to the previous position, reset back to HEAD@{1}:
If you prefer, you can also use the exact commit hash from the reflog instead of HEAD@{1}.
Undoing git reset --soft
git reset --soft moves HEAD but keeps the index and working tree unchanged. That means undoing it is usually easy because nothing in your files was discarded.
Example:
You can also use ORIG_HEAD, which Git often sets before commands that move HEAD significantly:
This restores the branch tip while keeping the staged state consistent with the original soft reset scenario.
Undoing git reset --mixed
A mixed reset, which is the default git reset, moves HEAD and updates the index, but it leaves the working tree alone. Your file contents are often still present, just unstaged.
To return to the prior commit:
If your goal is simply "put the branch back where it was," that is usually enough. After the reset back to the old commit, the index and working tree line up with that restored commit again.
If you had additional local edits after the mixed reset, inspect git status before doing anything destructive.
Undoing git reset --hard
This is the risky case. git reset --hard moves HEAD, resets the index, and rewrites the working tree to match the target commit.
If the lost state was committed, you can usually recover it through the reflog:
If the lost state existed only as uncommitted working-tree changes, git reset --hard may have deleted it permanently. Git tracks commits and many index states well, but it does not guarantee recovery of uncommitted file content after a hard reset.
That distinction matters:
- committed work is usually recoverable through reflog
- uncommitted work may not be recoverable
ORIG_HEAD as a Shortcut
Right after a reset, ORIG_HEAD often points to the previous HEAD:
This is convenient for a quick reversal when the reset was the very last history-changing action. If you have done more commands since then, git reflog is safer because it lets you see the exact sequence instead of guessing.
Safer Recovery Workflow
If you are unsure, make recovery incremental:
Creating a rescue branch first lets you inspect the recovered state before moving your current branch. That is safer than chaining more resets while you are already disoriented.
Common Pitfalls
The biggest mistake is assuming git reset --hard can always be undone. It can often restore lost commits, but it cannot reliably restore uncommitted edits that were never recorded anywhere in Git.
Another common issue is running more commands before checking the reflog. Recovery is usually still possible, but the reflog becomes harder to read and ORIG_HEAD may no longer point where you expect.
People also confuse undoing the branch pointer with restoring staged state. A soft reset, mixed reset, and hard reset affect different layers of the repository, so the "right undo" depends on what you actually want back.
Finally, if you already force-pushed rewritten history to a shared remote, local recovery is only part of the problem. You may also need to coordinate with teammates before repairing the branch remotely.
Summary
- The main recovery tool for undoing
git resetisgit reflog. - '
HEAD@{1}orORIG_HEADoften points to the state before the reset.' - Soft and mixed resets are usually easy to undo because file content is often still present.
- A hard reset can usually restore lost commits, but not necessarily uncommitted file changes.
- When unsure, recover to a new branch first and inspect the result before moving your main branch.
Related reading
- How do I undo the most recent local commits in Git?
- How do I update if exists, insert if not AKA upsert or merge in MySQL?
- How do I update or sync a forked repository on GitHub?
- How do I update the password for Git?
- How do I update the password for Git?
- How do I use git bisect?
- How do I use 'git reset --hard HEAD' to revert to a previous commit?
- How do I use 'git reset --hard HEAD' to revert to a previous commit?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.