⚡ ~/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) →
Senior DevOps / SRE [L2] Git Undo, Recovery & History Rewriting Production Scenario [L2]

Q: You merged a PR into `main` that turned out to be broken in production. The merge has been there for two hours and 15 commits have landed since. How do you back it out safely?

You can't reset main — it's shared and 15 other commits have built on top. The right tool is git revert, which creates a new commit that ...

#Git #Undo, Recovery & History Rewriting #L2 #Version Control #Collaboration #Rebase
🎙️ Candidate Opening & Architectural Context
""In a fast-paced team with dozens of pull requests merged daily, Git workflow hygiene was critical. The interviewer is testing: `git revert` on merge commits, understanding that you can't just delete published history.. 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

You can't reset main — it's shared and 15 other commits have built on top. The right tool is git revert, which creates a *new* commit that undoes the changes. For a merge commit you need -m to tell Git which parent to revert to (the "mainline"): -m 1 means "treat parent 1 (the main side) as the mainline, and revert everything that came in from the feature side." -m 2 would do the opposite. Push the revert. Now main is back to a working state and the 15 unrelated commits are preserved. Gotcha: if later you want to re-merge the fixed version of that feature branch, a plain merge will appear to do nothing because Git thinks those changes are already on main (they were, then reverted). You either revert the revert (git revert ) before re-merging, or rebase the feature branch onto current main so the commits get fresh hashes.

git revert -m 1 <merge-commit-sha>
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: You can't reset main — it's shared and 15 other commits have built on top. The right tool is git revert, which creates a *new* com."
⚡ 60-Second Elevator Pitch Talking Points
  • Immediate Triage: You can't reset main — it's shared and 15 other commits have built on top. The right tool is gi
  • 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