Interview Prep/Git & GitHub/Lost Work, HEAD and History Problems

`git reset --hard HEAD@{5}` fails with `fatal: bad revision 'HEAD@{5}'` or `git reflog` is empty.

IntermediateTroubleshootingLost Work, HEAD and History Problems
Answer

Likely causes → Fewer than six reflog entries exist, the reflog expired or was cleared (git reflog expire, gc), it is a fresh clone (reflogs are local), or you are in a different repository or worktree.

Diagnose →

git reflog | head
git config --get core.logAllRefUpdates
git reflog show origin/main

Fix → Look at other reflogs (git reflog show <branch>), search dangling commits with git fsck --lost-found, or fetch the lost work from a teammate or backup. Use dates: HEAD@{yesterday}.

Prevent → Push work-in-progress to a private branch, and avoid running git reflog expire --expire=now --all.

All Git & GitHub questions Roadmap: Git & GitHub

More on Lost Work, HEAD and History Problems