git
version control
undo
git reset
tutorial

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.

Browse interview questions

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:

bash
git reflog

You will see entries like:

text
3f2c1a0 HEAD@{0}: reset: moving to HEAD~1
8c4f7b2 HEAD@{1}: commit: add payment retry logic

If you want to undo the reset and return to the previous position, reset back to HEAD@{1}:

bash
git reset --hard 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:

bash
git reset --soft HEAD~1
git reflog
git reset --soft HEAD@{1}

You can also use ORIG_HEAD, which Git often sets before commands that move HEAD significantly:

bash
git reset --soft ORIG_HEAD

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:

bash
git reflog
git reset --mixed HEAD@{1}

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:

bash
git reflog
git reset --hard HEAD@{1}

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:

bash
git reset --hard ORIG_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:

bash
git reflog
git branch rescue HEAD@{1}
git switch rescue

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 reset is git reflog.
  • 'HEAD@{1} or ORIG_HEAD often 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.