Last Updated: May 1, 2025
Cherry-Pick Commands
git cherry-pick commitApply a single commit to the current branch
git cherry-pick commit1 commit2Apply multiple specific commits
git cherry-pick commit1..commit3Apply a range (commit1 exclusive, commit3 inclusive)
git cherry-pick commit1^..commit3Apply range INCLUDING commit1
git cherry-pick -x commitAppend '(cherry picked from commit SHA)' to message
git cherry-pick --no-commit commitStage changes without committing (review first)
git cherry-pick --signoff commitAdd Signed-off-by line to the commit message
git cherry-pick -m 1 merge-commitCherry-pick a merge commit (specify parent 1)
Handling Conflicts
git cherry-pick --continueAfter resolving conflicts, continue cherry-pick
git cherry-pick --skipSkip the current commit causing conflicts
git cherry-pick --abortAbort the entire cherry-pick operation
git cherry-pick --quitStop but keep changes in working tree
git statusCheck which files have conflicts during cherry-pick
git diffReview changes before committing
Common Use Cases
| Item | Description |
|---|---|
Backporting Hotfixes | Cherry-pick a fix from main to release branch |
Picking Features | Selectively move commits from experimental to stable branch |
Undeleting Code | Cherry-pick a commit that was reverted, after fixing the issue |
Cross-Team Sharing | Team A's utility commit needed by Team B's branch |
Splitting PRs | Cherry-pick specific commits from a large PR into smaller ones |
Restoring Stale Work | Revive commits from abandoned branches |
Duplicate Branch Fixes | Apply the same bugfix to multiple supported versions |
Avoid Merge Dependencies | Grab just the fix without merging an entire feature |
Cherry-Pick vs Alternatives
| Operation | Cherry-Pick | Merge | Rebase |
|---|---|---|---|
| Scope | Individual commits | Entire branch | Entire branch replays |
| History | Creates new commits | Preserves parent links | Rewrites commit SHAs |
| Use Case | Selective porting | Integrate work | Linearize history |
| Traceability | Use -x flag | Merge commit reference | Original context lost |
| Conflict Load | Per-commit conflicts | One merge conflict | Per-commit conflicts |
Pro Tip: Cherry-pick creates a new commit with a different SHA — use `-x` to add a reference to the original commit for traceability.