⚡ ~/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 8 of 52 in Git & Branching Workflows
Senior DevOps / SRE [L2] Git Undo, Recovery & History Rewriting Production Scenario [L2]
🎯 Target Role / Context: Git Scenario #8 (L2) · Undo, Recovery & History Rewriting

Q: You ran `git push --force` to your feature branch but realized you wiped out a teammate's commit they had pushed five minutes earlier. How do you recover their commit, and how do you prevent this next time?

The commit isn't lost on the remote yet — it's still in the remote's reflog and likely in your teammate's local repo. Recovery:

#Git #L2 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""Git is an immutable directed acyclic graph (DAG); knowing commands like git reflog means you never truly lose commits. The interviewer is testing: Reflog recovery, --force-with-lease, awareness of force-push hazards.. 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: "Git is an immutable directed acyclic graph (DAG); knowing commands like git reflog means you never truly lose commits. The interviewer is testing: Reflog recovery, --force-with-lease, awareness of force-push hazards.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."

1️⃣

Initial Diagnostics & Root Cause Analysis

The commit isn't lost on the remote yet — it's still in the remote's reflog and likely in your teammate's local repo. Recovery:

  • Ask the teammate — their local branch still has the commit. They can push it back (after pulling your changes and rebasing it on top), or share the hash.
  • Check the remote's reflog if you have shell access to the server (rare on managed services). On GitHub, the events API and "Network" graph sometimes still show the dangling commit hash for a while; you can fetch it directly: git fetch origin .
  • Check your own clone — if you fetched their commit before force-pushing, git reflog on the remote-tracking branch (git reflog show origin/feature-x) will list it. Cherry-pick it back: git cherry-pick then push.
  • Use git push --force-with-lease instead of --force. It refuses to push if the remote has commits you haven't seen — exactly this scenario.
2️⃣

Remediation & Permanent Safeguards

Prevention:

  • Better: git push --force-if-includes (Git 2.30+) — also verifies your local ref includes the latest fetch.
  • Branch protection rules on main/develop should block force-push entirely. Force-push should only be allowed (and only via --force-with-lease) on personal feature branches.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Ask the teammate — their local branch still has the commit. They can push it back (after pulling your changes and rebasing it on t."
⚡ 60-Second Elevator Pitch Talking Points
  • Ask the teammate — their local branch still has the commit. They can push it back (after pulling ...
  • Check the remote's reflog if you have shell access to the server (rare on managed services). On G...
  • Check your own clone — if you fetched their commit before force-pushing, git reflog on the remote...
⛔ 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 push force feature 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 push force feature 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 push force feature 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 push force feature 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 →