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:
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: "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."
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.
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
- 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...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring critical commit exists
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring critical commit exists Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring critical commit exists
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring critical commit exists Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.