Q: A critical bug-fix commit exists on `develop` and you need exactly that one commit on a release branch — without bringing along the other 50 commits on `develop`. How do you do it, and what could go wrong?
This is git cherry-pick:
#Git #Collaboration & Remote Workflows #L2 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""When an engineer accidentally creates this branch or commit divergence, I walk them through safe recovery without data loss. The interviewer is testing: Cherry-pick mechanics and its hazards.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
This is git cherry-pick:
- Conflicts — if the surrounding code on
release/1.4is different fromdevelop, the patch may not apply cleanly. Resolve, thengit cherry-pick --continue. - Missing dependencies — the commit may rely on a refactor or a helper that was introduced in an earlier commit on
developbut isn't onrelease/1.4. The cherry-pick may apply but the code won't compile or behave correctly. You may need to cherry-pick the prerequisite commit too, or write a backport patch. - Duplicate-looking commits — when
developis later merged intorelease(or vice versa), Git usually figures out the commits are equivalent (via patch-id), but in some workflows you can end up with two commits doing the same thing under different SHAs. Usegit cherry-pick -xto record "(cherry picked from commit …)" in the message — invaluable later for traceability.
2️⃣
Remediation & Permanent Safeguards
Cherry-pick takes the diff that commit introduced and applies it as a *new* commit on the current branch (new SHA, same content). For multiple commits: git cherry-pick or a range git cherry-pick A..B. What can go wrong: For ongoing back-port flows (fix on main, port to release/*), some teams prefer a dedicated hotfix/* branch that's merged into both, which avoids cherry-picks entirely.
git switch release/1.4
git cherry-pick <commit-sha>
git push
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Conflicts — if the surrounding code on release/1.4 is different from develop, the patch may not apply cleanly. Resolve, then git c."
⚡ 60-Second Elevator Pitch Talking Points
- Conflicts — if the surrounding code on release/1.4 is different from develop, the patch may not a...
- Missing dependencies — the commit may rely on a refactor or a helper that was introduced in an ea...
- Duplicate-looking commits — when develop is later merged into release (or vice versa), Git usuall...
Advertisement