You must backport 15 commits to three old release branches. How do you make it repeatable?
AdvancedScenarioRebase, Cherry-pick and History Rewriting
Answer
Situation read → Doing 45 cherry-picks by hand is error-prone.
What I'd do →
- Collect the commits in order:
git rev-list --reverse --no-merges <range> > picks.txt. - Script it per branch:
for br in release/3.8 release/3.9 release/4.0; do
git switch -c "backport-$br" "origin/$br"
xargs -n1 git cherry-pick -x < picks.txt || break
git push origin "backport-$br"
gh pr create --base "$br" --fill
done
- Stop on the first conflict and fix by hand; let CI test each PR.
- Prefer a bot (GitHub Action with labels such as
backport 4.0) for the long run.
Why → Oldest-first order matters, since later commits assume earlier ones.
Interview tip → Mention using PR labels to trigger automated backports.
More on Rebase, Cherry-pick and History Rewriting
Your PR branch has ten commits like "wip", "fix typo", "oops". How do you clean it up before review?BeginnerYou want the database migration commit to come before the code that uses it.BeginnerA critical fix on `main` must go to the `release/4.1` branch only.BeginnerYou must backport a feature made of 6 commits, including one merge commit.IntermediateBranch B was built on top of branch A. A was squash-merged into `main`, and now B shows A's commits again.IntermediateDuring review you get ten small change requests on old commits. How do you apply them cleanly?Intermediate