Interview Prep/Git & GitHub/Undoing Mistakes

You dropped a stash entry accidentally and need it back.

AdvancedScenarioUndoing Mistakes
Answer

Situation read → A dropped stash is an unreachable commit; Git printed its SHA when you dropped or popped it.

What I'd do →

  1. If you saw Dropped refs/stash@{0} (abc123...), run git stash apply abc123.
  2. Otherwise search dangling commits:
git fsck --no-reflogs --unreachable | awk '/commit/ {print $3}' \
  | xargs git log --no-walk --format='%h %ad %s' --date=short
  1. Look for "WIP on <branch>" messages and apply the right one with git stash apply &lt;sha>.

Why → A stash is a merge commit with two or three parents; it stays until pruned.

Interview tip → Do this fast, and avoid running git gc.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes