Journeys · Git · L1

Recovering a lost commit with the reflog

git reset --hard moves main back and the commit vanishes from git log. The reflog still knows where it is.

✓ Validated on Git 2.43.0 · Run 1 · 2026-11-21Preview

The 30-second answer

git reset --hard moves main back and rewrites your files, but it deletes no object. The commit is still in the object store. No branch points at it any more, but the reflog does: every time HEAD or a branch moves, Git writes the old id and the new id to a log under .git/logs. git reflog reads that log. Point main back at the old id and everything returns. The reflog is local and it expires: entries for commits no longer on the branch go after 30 days by default. After that, git gc may delete the commit for good.

Mental model

A ship's logbook. Each time the captain changes course, the officer writes the old heading and the new one. Turn back by mistake and the lost course is still written in the log, so you can steer it again.

Where the analogy breaks

A ship's log is kept forever and shared with the owners. Git's reflog is in your clone only, nobody else can read it, and old pages are torn out on a schedule.

🔒 Free account

Sign up free to play this journey

A free account unlocks every scenario, journey and exam, and saves your progress. No payment, ever.