Interview Prep/Git & GitHub/Undoing Mistakes

You think commits were lost and the reflog entry has expired. Can anything still be found?

AdvancedScenarioUndoing Mistakes
Answer

Situation read → If gc has not pruned the objects yet, they exist as dangling commits even without reflog entries.

What I'd do →

  1. git fsck --lost-found --no-reflogs lists dangling commits and blobs.
  2. Inspect: git show <sha> or git log -1 <sha>.
  3. Rescue: git branch recovered <sha>.
  4. Stop all git gc activity: git config gc.auto 0.

Why → Pruning happens only after gc.pruneExpire (default 2 weeks) for unreachable objects.

Interview tip → Also ask whether a teammate, CI runner or fork has a copy.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes