Copy One Commit
Switch to the branch that should receive the commit, then name the commit:
git log --oneline develop -10
git switch main
git cherry-pick a1b2c3dGit applies the changes of a1b2c3d on top of main and makes a new commit with the same message and author. The new commit has a different hash, because its parent is different. The original stays on develop.
To find a commit by its message on any branch, search the log:
git log --oneline --all --grep="login"The short hash at the start of each line is enough for cherry-pick. A branch name also works and means the commit at its tip, so git cherry-pick develop copies the latest commit of develop.
Copy Several Commits
List the hashes in the order you want them applied, usually oldest first:
git cherry-pick a1b2c3d e4f5a6bCopy a Range
| Form | First commit of the range |
|---|---|
A. | Not included |
A^. | Included |
git cherry-pick a1b2c3d^..f6e5d4cBoth forms take the commits up to and including B, oldest first. The caret means "the parent of", so A^..B starts one step earlier and includes A. Check the range first with git log --oneline A^..B.
Useful Options
-x: adds a line to the message saying which commit it was cherry-picked from (only when the pick has no conflicts). Use it for fixes copied to release branches, so the link is visible later.-n: applies the changes without committing, so you can combine several commits or edit before you commit. The long form is--no-commit.-e: opens the editor so you can change the message.-m 1: needed to cherry-pick a merge commit; it applies the changes relative to the first parent.
git cherry-pick -x a1b2c3dResolve Conflicts
If the target branch changed the same lines, Git stops and marks the conflict in the files:
git status
git add src/payment.js
git cherry-pick --continueFix each file that git status lists, remove the conflict markers, add the file, and continue. With a range, Git then goes on with the next commit.
git cherry-pick --abort: cancels the whole operation and returns the branch to where it was.git cherry-pick --skip: drops the current commit and goes on with the next.- An empty commit: if the change is already on the target branch, Git stops and says the result is empty. Skip it.
To put the current changes aside before you start, use git stash: Git documents that cherry-pick needs a clean working tree.
Undo a Cherry-Pick
If the new commit is not pushed, remove it with git reset --hard HEAD~1, after checking git status for uncommitted work, as explained in git reset explained. If it is pushed, use git revert instead, which undoes it with a new commit.
When Merge or Rebase Is Better
Cherry-pick copies commits; it does not record that the branches share them. Git sees two different commits with the same change, which can lead to confusing history and repeated conflicts when the branches are merged later.
- One or two fixes for a release branch: cherry-pick with
-x. - All the work of a branch: merge it.
- A branch that should sit on a newer base: rebase it.
The difference between the last two is explained in git merge vs rebase.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations