Skip to main content

Recovery with Reset, Stash, and Reflog

What This Concept Is

Git recovery tools let you move work around safely when you make mistakes or need to pause unfinished work.

The three core tools here are:

  • git reset: move a branch pointer and optionally align index or working tree
  • git stash: shelve unfinished work temporarily
  • git reflog: inspect where your local references used to point

Why It Matters Here

You do not need to avoid all Git mistakes. You need to avoid panicking when they happen. Recovery is much easier when you know whether you are changing:

  • a reference
  • the index
  • the working tree

That is why reset feels dangerous to beginners. It can touch more than one layer.

Concrete Example

Common safe patterns:

git stash push -m "wip before branch switch"
git switch main
git reset --soft HEAD~1

This undoes the last commit but keeps the changes staged.

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

This can recover from a bad local move if the old position still exists in the reflog.

Common Confusion / Misconception

Misconception: reset is one thing.

Correction: reset --soft, default reset, and reset --hard do very different amounts of damage because they touch different layers.

Misconception: Once a branch tip moves, the old commit is gone forever.

Correction: Reflog often gives you a recovery window for local reference movements.

How To Use It

Default safety rule:

  • if you are not fully sure, stash or branch before destructive operations

Practical rule of thumb:

  • stash for temporary shelving
  • reset --soft for local commit redo
  • default reset for unstaging
  • reset --hard only on throwaway or fully understood state
  • reflog when you need to find where you were before

Check Yourself

  1. What is the difference between reset --soft and reset --hard?
  2. Why is reflog local rather than shared?
  3. Why is stash often the safer first move before risky cleanup?

Mini Drill or Application

In a throwaway repository:

  1. create two commits
  2. run git reset --soft HEAD~1
  3. inspect status
  4. recommit
  5. make more uncommitted edits and stash them
  6. run git reflog
  7. deliberately move away from a commit and recover it with the reflog

Write one sentence for each step explaining which layer changed.

Read This Only If Stuck