Interview Prep/Git & GitHub/Undoing Mistakes

You ran `git reset --hard` and lost uncommitted-then-committed work. Can you get it back?

IntermediateScenarioUndoing Mistakes
Answer

Situation read → If the work was ever committed, the commits still exist as unreachable objects and the reflog records where HEAD was.

What I'd do →

  1. git reflog and find the entry before the reset, such as HEAD@{2}.
  2. Restore: git reset --hard HEAD@{2}, or safer, git branch rescue HEAD@{2}.
  3. Verify with git log rescue.

Why → Reflog entries last 90 days for reachable and 30 days for unreachable commits by default.

Interview tip → Work that was never staged or committed is gone; reset --hard cannot be undone for those changes.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes