git cherry-pick Command Guide
Apply the changes introduced by some existing commits
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
git cherry-pick <commit>Pick single commitgit cherry-pick A B CPick multiplegit cherry-pick A..BPick rangeOptions
-n, --no-commitDon't auto-commit-e, --editEdit commit message-xAdd source info to messageControl
--continueContinue after conflict--abortAbort cherry-pick--skipSkip current commitDownloadable Image Preview
Basic Usage
The git cherry-pick command applies the changes from one or more existing commits to your current branch. It's useful for selectively moving commits.
# Cherry-pick a single commit
git cherry-pick abc1234
# Cherry-pick from another branch
git log feature --oneline # Find the commit
git checkout main
git cherry-pick abc1234Cherry-picking Multiple Commits
# Pick multiple commits
git cherry-pick abc1234 def5678 ghi9012
# Pick a range (exclusive of first commit)
git cherry-pick abc1234..ghi9012
# Pick a range (inclusive)
git cherry-pick abc1234^..ghi9012
# Pick all commits from a branch
git cherry-pick main..featureA..B excludes commit A. Use A^..B to include commit A.Common Options
| Option | Description |
|---|---|
| -n, --no-commit | Apply changes without committing |
| -e, --edit | Edit the commit message |
| -x | Append source commit info to message |
| --continue | Continue after resolving conflicts |
| --abort | Cancel cherry-pick operation |
# Cherry-pick without committing (review first)
git cherry-pick --no-commit abc1234
# Add reference to original commit
git cherry-pick -x abc1234
# Message: "... (cherry picked from commit abc1234)"
# Edit the commit message
git cherry-pick -e abc1234Handling Conflicts
# When conflicts occur
git cherry-pick abc1234
# CONFLICT: Merge conflict in file.js
# Fix conflicts in the file
# Then stage and continue
git add file.js
git cherry-pick --continue
# Or skip this commit
git cherry-pick --skip
# Or abort entirely
git cherry-pick --abortPractical Examples
# Backport a fix to release branch
git checkout release-1.0
git cherry-pick abc1234 # The fix commit
# Apply hotfix from main to multiple releases
git checkout release-1.0
git cherry-pick -x abc1234
git checkout release-2.0
git cherry-pick -x abc1234
# Apply multiple related commits
git cherry-pick abc1234 def5678 -n
git commit -m "Combined feature from branch X"
# Cherry-pick from a specific branch
git cherry-pick feature~3 # 3rd commit before tip of featureCommon Use Cases
- • Backporting bug fixes to release branches
- • Applying specific commits without merging entire branch
- • Moving commits to the correct branch
- • Selective feature deployment
Frequently Asked Questions
What is cherry-picking in Git?
Cherry-picking applies the changes from a specific commit to your current branch. It creates a new commit with the same changes but a different commit hash.
When should I use cherry-pick?
Use cherry-pick to apply specific commits from one branch to another, like backporting a bug fix to a release branch or applying a hotfix from one branch to main.
Does cherry-pick copy or move commits?
Cherry-pick copies commits. The original commit stays on its branch, and a new commit with the same changes is created on your current branch.
What happens if cherry-pick has conflicts?
Git stops and lets you resolve conflicts. After fixing them, run "git add" on resolved files and "git cherry-pick --continue" to finish.
Summary
git cherry-pick lets you apply specific commits across branches. Use -x to track where commits came from.
Quick Reference
git cherry-pick <commit>- Pick commitgit cherry-pick A..B- Pick rangegit cherry-pick -n- Without commitgit cherry-pick -x- Add source info
Official Documentation
For authoritative information, refer to the official documentation: