Table of contents
Choose commits that stand alone
Inspect the candidate commit and its neighbors. If the change depends on prior refactors, pick the dependency chain or use a different integration strategy.
Use `git show` and tests to confirm what the commit changes and what assumptions it makes.
Apply with traceability
Use `-x` so the resulting commit message records the original source hash. This keeps audit trails intact across maintenance branches.
Handle conflicts as first-class merges. Validate behavior in the target branch context, not only the source branch context.
Close with explicit validation
Run targeted tests for the picked area plus branch-specific regression checks. Re-read the final diff against the destination branch.
When backporting to release branches, document risk and rollout/rollback notes in the PR description.
Worked example: backport a fix without its unrelated refactor
Imagine main contains a refactor commit R followed by a bug fix F. The release branch needs the bug fix but does not contain the refactor. Before picking F, inspect whether it calls a helper introduced by R. Applying F cleanly can still break the release if that helper does not exist there.
Use git show with the selected commit and inspect its tests and neighboring commits. If it depends on the refactor, either backport the reviewed prerequisite chain or write a smaller release-specific equivalent. Do not pick an entire chain only because it silences the first missing import.
Source and target histories
main: A---R---F
release: A---PTargeted pick, after reviewing dependencies
git switch release
git status
git cherry-pick -x <fix-commit>Resolve against the release branch, not just the original patch
When a pick conflicts, inspect git status and the destination implementation. A release-only change may need to survive alongside the bug fix. Use MergeGlass on copies of the relevant sources to compare the alternatives, but judge the result against the release’s API, dependencies, and test behavior.
Write the selected candidate into the working-tree path, stage only the resolved files, and use git cherry-pick --continue. If the pick is wrong, git cherry-pick --abort stops the active sequence. If Git reports an empty pick, inspect whether the behavior is already present before deciding to skip it.
Picking a merge commit requires choosing a mainline parent, which changes which patch Git replays. If you cannot explain the parent choice, stop and inspect the history. Prefer the original focused fix commit when it is available and actually contains the desired behavior.
Prove the fix in the target environment
First reproduce the release bug using a focused regression check, then verify that the backport fixes it. Run the required release checks with that branch’s dependencies. A test that passes on main may rely on an implementation or toolchain absent from the release.
Inspect the final diff against the release base for unrelated edits, generated files, and assumptions imported from main. Use the -x record and review notes to explain where the fix came from, any adaptation you made, and how to roll back through the normal release process.
For this example, success is the intended correction on top of P without accidentally introducing R. If the fix cannot be separated safely, raise that constraint in review instead of describing a broader refactor as a small backport.
Try it yourself
Resolve one conflict with a common base
Both sides changed timeoutMs. For this fictional requirement, keep B’s 10000ms timeout and its independent retries change. This practice compares file contents; it does not run Git.
Try this example adds fictional sample data as a separate file review and keeps your existing reviews.
The download is a standalone practice session. Save your current work before importing it through Add or import → Import review bundle. Your own content is never included in the download.
Command checklist
git show <commit>git cherry-pick -x <commit>git cherry-pick --abortgit log --oneline --decorate -n 20git diff origin/release..HEAD
Review checklist
- Verify the commit is self-contained.
- Use `-x` to preserve source traceability.
- Resolve conflicts with full context.
- Run target-branch validation tests.
- Document rollout and rollback notes.