Git 2 reference · Branching and Merging
git cherry-pick Command (Git)
Apply the changes of specific commits from another branch onto the current branch as new commits.
Git 2
Syntax
git cherry-pick [-x] COMMIT...
Parameters
| Parameter | Description |
|---|---|
-x |
Add '(cherry picked from commit ...)' to the message. |
--continue / --abort |
After conflicts. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c develop
echo fix > fix.txt; git add .; git commit -q -m 'Fix checkout bug'
echo wip > wip.txt; git add .; git commit -q -m 'WIP feature'
git switch -q main
git cherry-pick -x develop~1 > /dev/null
git log --format='%s%n%b' -1
Output
Fix checkout bug (cherry picked from commit 7cad6a3de1e2da23af3db909283783a9cd7e984f)
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c b; echo 1 > one.txt; git add .; git commit -q -m one; echo 2 > two.txt; git add .; git commit -q -m two
git switch -q main; git cherry-pick b~1 b > /dev/null
git log --oneline
Output
dcec621 two ddcd6fc one 7f7f133 Initial commit
Run this on your computer — see “Get Started” for setup.
Related
git rebase· Replay your branch's commits on top of another branch for a linear history, or clean up commits with -i before sharing.git revert· Create a new commit that undoes an earlier commit's changes; the safe way to undo commits that were already pushed.- Rebasing · tutorial