⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ 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) →
← Back to All Git & Branching Workflows Interview Questions Scenario 11 of 52 in Git & Branching Workflows
Staff SRE / Principal Architect [L3] Git Undo, Recovery & History Rewriting Staff SRE Scenario [L3]
🎯 Target Role / Context: Git Scenario #11 (L3) · Undo, Recovery & History Rewriting

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.

#Git #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
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: "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."

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.

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.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring junior reset hard git push --force unconditionally overwrites remote commits made by teammates, whereas --force-with-lease aborts if the remote ref was updated.
  2. Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring junior reset hard Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
  3. Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring junior reset hard git reflog tracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches.
  4. Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring junior reset hard Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.
Advertisement
Want more Git & Branching Workflows scenarios?
Explore our complete collection of scenario-based Git & Branching Workflows interview runbooks.
Browse All Git & Branching Workflows Questions →