⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 998+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Staff SRE / Principal Architect [L3] Git Undo, Recovery & History Rewriting Staff SRE Scenario [L3]

Q: A junior engineer ran `git reset --hard HEAD~5` on their local branch and lost five commits of in-progress work. Nothing was pushed. Walk me through the recovery.

A --hard reset moves the branch pointer and discards working-tree changes — but the commits themselves are not deleted. They're orphaned ...

#Git #Undo, Recovery & History Rewriting #L3 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""During a major release branch cut, we encountered this exact scenario and used Git internals to recover cleanly. The interviewer is testing: Deep understanding of refs, reflog, and Git's garbage collection model.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement

🛠️ Production Runbook & Step-by-Step Resolution

1️⃣

Production Solution & Architecture

A --hard reset moves the branch pointer and discards working-tree changes — but the commits themselves are not deleted. They're orphaned (no branch points to them) and will sit in the object database until garbage collection runs (default: ~30 days for unreachable objects, 90 days if reachable from reflog). Recovery via the reflog, which is a per-clone log of every move HEAD (and each branch ref) has made: You'll see something like: def5678 is the tip of the work that was wiped. Restore it: Two important caveats: (1) the reflog is local — it doesn't help if the commits never existed on this clone (e.g. teammate's machine). (2) Run recovery *before* git gc runs. If you suspect a teammate already ran git gc --prune=now, the objects may genuinely be gone. As a habit, alias reset --hard to require confirmation, and teach the team git stash and git switch -c backup before risky operations. --- ## 🟡 Collaboration & Remote Workflows

git reflog                       # shows HEAD movements
# or, more targeted:
git reflog show feature-branch   # shows that branch's history
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: A --hard reset moves the branch pointer and discards working-tree changes — but the commits themselves are not deleted. They're or."
⚡ 60-Second Elevator Pitch Talking Points
  • Immediate Triage: A --hard reset moves the branch pointer and discards working-tree changes — but the commits the
  • Run targeted verification commands before modifying configuration.
  • Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Advertisement
Want more Git scenarios?
Explore our complete collection of scenario-based Git interview runbooks.
Browse All Git Questions →

📚 Related Production Scenarios in Git