Gitflow
👻Lost Commits After Hard ResetHard+700 XP
Workshop
Scenario reference

Lost Commits After Hard Reset: the situation, step by step

The situation

You ran `git reset --hard HEAD~5` to 'clean up', then realized 3 of those commits weren't pushed anywhere. Panic.

The commits exist in the reflog for ~90 days. Reflog is your time machine.

Hard · 5 steps · +700 XP

What you will practice

This scenario walks through 5 steps, in order:

  1. 01Check the reflog for lost HEADs
  2. 02Inspect the commit you want back
  3. 03Create a recovery branch pointing at the lost commit
  4. 04Switch to the recovery branch and verify
  5. 05Confirm with log
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Check the reflog for lost HEADs
    git reflog
  2. 2. Inspect the commit you want back
    git show HEAD@{5}
  3. 3. Create a recovery branch pointing at the lost commit
    git branch recovery HEAD@{5}
  4. 4. Switch to the recovery branch and verify
    git switch recovery
  5. 5. Confirm with log
    git log --oneline

Key takeaway

Reflog saves lives. Reset --hard is reversible — until gc runs.