cherry-pick
Git · Reference cheat sheet
cherry-pick
Git · Reference cheat sheet
📋 Overview
git cherry-pick applies the patch of one or more existing commits onto the current branch as new commits. Use to backport fixes; avoid heavy cherry-picking as a substitute for proper merges/rebases.
🔧 Core concepts
- New SHAs — picked commits get new hashes (same diff, new parents).
- Ranges —
A^..Bor--no-walkfor explicit lists. - Mainline —
-m 1when picking merge commits. - Continue — conflict → fix →
--continue/--abort/--skip. - Sign-off —
-xrecords “cherry picked from” in the message.
💡 Examples
git checkout release/1.2
git cherry-pick abcdef1
git cherry-pick -x abcdef1 # note source SHA in message
# Multiple
git cherry-pick abcdef1 1234567
git cherry-pick A^..B
# No auto-commit
git cherry-pick --no-commit abcdef1
# During conflicts
git status
# fix files
git add -u
git cherry-pick --continue
# or
git cherry-pick --abort⚠️ Pitfalls
- Duplicate commits later when merging the original branch (duplicate changes / conflicts).
- Empty cherry-pick if changes already present —
--skipor abort. - Merge commits need
-m; picking merges is often the wrong tool. - Don’t cherry-pick unpublished WIP that will be rewritten (amended/rebased).
- Binary conflicts and renames can make picks painful — prefer merge for large sets.