The way a cherry-pick works is by taking the diff a changeset represents (the difference between the working tree at that point and the working tree of its parent), and applying it to your current branch.

So, if a commit has two or more parents, it also represents two or more diffs - which one should be applied?

You're trying to cherry pick fd9f578, which was a merge with two parents. So you need to tell the cherry-pick command which one against which the diff should be calculated, by using the -m option. For example, git cherry-pick -m 1 fd9f578 to use parent 1 as the base.

Parent 1 is the "first parent", 2 is the "second parent", and so on. The order is the one in which they're listed in the commit (as viewed by git show and the like).

I can't say for sure for your particular situation, but using git merge instead of git cherry-pick is generally advisable. When you cherry-pick a merge commit, it collapses all the changes made in the parent you didn't specify to -m into that one commit. You lose all their history, and glom together all their diffs. Your call.

Answer from Borealid on Stack Overflow
Top answer
1 of 6
986

The way a cherry-pick works is by taking the diff a changeset represents (the difference between the working tree at that point and the working tree of its parent), and applying it to your current branch.

So, if a commit has two or more parents, it also represents two or more diffs - which one should be applied?

You're trying to cherry pick fd9f578, which was a merge with two parents. So you need to tell the cherry-pick command which one against which the diff should be calculated, by using the -m option. For example, git cherry-pick -m 1 fd9f578 to use parent 1 as the base.

Parent 1 is the "first parent", 2 is the "second parent", and so on. The order is the one in which they're listed in the commit (as viewed by git show and the like).

I can't say for sure for your particular situation, but using git merge instead of git cherry-pick is generally advisable. When you cherry-pick a merge commit, it collapses all the changes made in the parent you didn't specify to -m into that one commit. You lose all their history, and glom together all their diffs. Your call.

2 of 6
270

-m means the parent number.

From the git doc:

Usually you cannot cherry-pick a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows cherry-pick to replay the change relative to the specified parent.

For example, if your commit tree is like below:

- A - D - E - F -   master
   \     /
    B - C           branch one

then git cherry-pick E will produce the issue you faced.

git cherry-pick E -m 1 means using D-E, while git cherry-pick E -m 2 means using B-C-E.

🌐
Medium
medium.com › @hamida.meknassi › cherry-picking-from-a-merge-request-commit-git-cherry-pick-m-de5be4e1f286
Cherry-picking from a Merge request commit : git cherry-pick -m | by Hamida Meknassi | Medium
February 20, 2024 - This happens because when you attempt to cherry-pick a merge commit, Git needs to determine which side of the merge should be considered the mainline because cherry-picking involves replaying changes relative to a specific parent.
Discussions

Can you cherry-pick pull requests??
What I often do is cherry pick using -m1 argument. I suppose what you want to cherry pick is the changeset of the pull-request. So if the pull-request is already merged into the main branch you can just cherry pick this merge. But since a merge commit has two parents you must select one to determine the changeset the cherry pick will apply, hence the -m1 which means 'first parent'. I advise you to look at the cherry pick help page if you need further info. More on reddit.com
🌐 r/git
19
2
March 30, 2024
Gerrit workflow: Cherry-picking vs merging?
To each their own. Cherry picking really is about taking just what you need from one branch to another. Merging is about bring it all over (regardless of that's with a merge commit or not (via rebase)). If you're development branch has very good atomic commits, and your main branch for releasing only needs a few of those things for the release cycle, cherry picking is a fine approach. More on reddit.com
🌐 r/git
6
8
April 20, 2023
git - What are the pros and cons of using cherry-pick versus merge for release management? - Software Engineering Stack Exchange
Folks will commit relevant content to release1, and we'll need that content in dev for the next releases. The obvious solution (to me) is to git merge release1 to dev occasionally (completing the merge PRs with merge, not squash!). However, most devs are used to cherry-picking their changes ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
November 5, 2024
git - How to cherry-pick merge commits? - Stack Overflow
I need to cherry pick a range of commits, where I found commits like this: Merge "TICKET-100: Some commit message" into master TICKET-100: Some commit messa... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Git
git-scm.com › docs › git-cherry-pick
Git - git-cherry-pick Documentation
Usually you cannot cherry-pick a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows cherry-pick to replay the change relative to the specified parent. ... Usually the command automatically creates a sequence of commits.
🌐
GitLab
docs.gitlab.com › topics › git › cherry_pick
Cherry-pick changes with Git | GitLab Docs
Identify the SHAs of the commits you want to cherry-pick. To find this, check the commit history or use the git log command. For example, if the code change is in one commit and improved test coverage is in the next commit: $ git log commit abc123f Merge: 88888999999 aaaaabbbbbb Author: user@example.com Date: Tue Aug 31 21:19:41 2021 +0000 Fixes a regression we found yesterday commit ghi456j Merge: 44444666666 cccccdddddd Author: user@example.com Date: Tue Aug 31 21:19:41 2021 +0000 Adds tests to ensure the problem does not happen again
🌐
Matt Stauffer
mattstauffer.com › blog › how-to-merge-only-specific-commits-from-a-pull-request
How to merge only specific commits from a pull request with git cherry-pick | MattStauffer.com
Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here.
🌐
Microsoft
devblogs.microsoft.com › dev blogs › the old new thing › stop cherry-picking, start merging, part 1: the merge conflict
Stop cherry-picking, start merging, Part 1: The merge conflict - The Old New Thing
September 1, 2023 - All through this, the victim branch is blithely unaware of the cherry-picking disaster being created by the feature and master branches. It commits changes V2 and V3 which have nothing to do with the line in question, so the line is still apple. Eventually, the feature branch merges its changes back into the victim branch, producing commit V4, where the line in question is now cherry, thanks to the changes that were made in the feature branch.
Find elsewhere
🌐
Reddit
reddit.com › r/git › can you cherry-pick pull requests??
r/git on Reddit: Can you cherry-pick pull requests??
March 30, 2024 -

Using git for quite some time but never ran into an issue where I want to cherry-pick a pull request. I know you can cherry-pick individual commits, but the PR contains around 50 commits, so is there a short way to do it??

🌐
Reddit
reddit.com › r/git › gerrit workflow: cherry-picking vs merging?
r/git on Reddit: Gerrit workflow: Cherry-picking vs merging?
April 20, 2023 -

Just wondering because of the workflow we have in our industry projects:

  • All commits go through a code review process via Gerrit.

  • The master branch is kept strictly linear. When there is a feature branch, it ultimately eventually gets squashed into or rebased onto the master branch.

  • At some point, a release branch is split off from the master branch. After that, most commits are usually still cherry-picked between release and master. Generally, all commits of the release branch are also on the master branch, but risky changes are only on master.

So the history looks something like

··· -- A -- B -- C -- D -- R1 -- E -- F -- G -- R2 -- H (master)
        `-- B'-- C'-- D'-------- E'-- F'-- G'-------- H'(release)

This made me wonder, if it would be more accurate to commit to release and merge to master. Which, to be fair, looks a lot messier:

··· -- A -- B -- C -- D -- R1 -- E -- F -- G -- R2 -- H (master)
        \  /    /    /          /    /    /          /
         B' -- C'-- D'-------- E'-- F'-- G'-------- H' (release)

I can see the advantage of keeping the master history a straight line, but are there also issues with that approach by losing the actual relationship between the commits?

Note that the code review interface of Gerrit clearly favors the cherry-pick approach, even though this can result in non-conflicting commits having different order between master and release branch (which I guess doesn't really matter for anything).

🌐
Better Programming
betterprogramming.pub › git-cherry-pick-selecting-specific-commits-to-merge-f1bf245e052a
Git Cherry Pick - Select specific commits to merge | by Carlos Fernando Arboleda Garcés | Better Programming
December 13, 2023 - git checkout main_cherry_pick git cherry-pick 12670fd 14b185a df931e3 1441727 2296bb0 · If you don’t have any conflict, you will see one commit confirmation for each selected/included commit in your cherry-pick command: ... Finally, you need to push the changes in your main_cherry_pick to the remote branch. Then you have to do a normal merge from main_cherry_pick into the main branch.
🌐
Atlassian
atlassian.com › git › tutorials › cherry pick
Git Cherry Pick | Atlassian Git Tutorial
December 15, 2025 - Git cherry-pick is a useful tool when merging several branches together but not always a best practice. Learn when, how and where to use it!
Top answer
1 of 2
2

Merging provides a clearer and more complete picture of the changes leading up to each feature release or bug fix, making it easier for developers to trace back and understand why certain decisions were made. Cherry-picking can create fragmented or isolated commits, which makes tracking the development history and debugging more complex. It also increases the risk of human error, such as accidentally omitting commits, including those that other changes depend on. In practical terms, if you cherry-pick only some commits from a sequence with dependencies, you might end up with code that fails to compile, causes bugs, or doesn’t reflect the intended feature because the cherry-picked commits lack the full context. Merging, on the other hand, preserves the order and structure of dependent commits, reducing these risks.

If you are not using CI at the moment, and if you decide to go that way in future, merging is more CI-friendly. In my experience, CI tools (Jenkins springs to mind) handle branch merges much better than workflows that rely on individual cherry-picked commits, which are applied one-by-one to the target branch. Proper merging creates more stable integration points and enables smoother automation, both of which support reliable testing and deployment.

Merging is widely adopted as a best practice because it preserves commit history and dependencies, supporting a stable and predictable workflow. This also simplifies onboarding, as new team members are likely familiar with standard git workflows.

Finally, depending on how your company handles releases, merging provides the QA team with a consistent and complete set of changes. This makes test planning and execution more straightforward, reducing the risk of missing dependencies or introducing regressions. Unlike cherry-picking, merging allows QA to validate cohesive features or fixes in one go, minimising repeated testing and simplifying communication around what is included in each build. Additionally, merging enhances CI integration, making automated tests more reliable and reducing manual checks, so QA can focus on thorough testing rather than troubleshooting incomplete changes.

2 of 2
0

Some details about the git flow the team uses could help getting answers closer to what you are looking for than How do I explain ${something} to ${someone}? that has been mentioned in comments.

From description it seems there are several branches constantly out of sync, the team is uncertain about what branch the code in production has been released. dev branch is behind the release branch while it should be the other way around, the dev branch it should be ahead of production code and that's why the team finds git cherry-pick more convenient than merge. Is the dev a development slow down? 'cause this is what it seems to happen. I would say a redesign of the git flow the team follows would shed a different light over the git commands the team members use.

🌐
Git Tower
git-tower.com › learn › git faq › git cherry pick - how to use the "cherry-pick" command in git
Git Cherry Pick - How to use the "cherry-pick" command in Git | Learn Version Control with Git
With the "cherry-pick" command, Git allows you to integrate selected, individual commits from any branch into your current HEAD branch. Contrast this with the way commit integration normally works in Git: when performing a Merge or Rebase, all ...
Published   5 days ago
🌐
GitLab
genboree.org › help
Cherry pick changes · Merge requests · Project · User · Help · GitLab
Optional. Select Start a new merge request with these changes. Select Cherry-pick. You can cherry-pick a single commit from multiple locations in your GitLab project.
🌐
GitHub
github.com › mermaid-js › mermaid › issues › 4497
Unable to cherry-pick a merge commit · Issue #4497 · mermaid-js/mermaid
June 16, 2023 - While merge commits can now be given an ID (presumably implemented in #3238), that ID cannot be leveraged for cherry-picking - at least in the MWE given below. Seems to be caused by c147404 (#3080). See live editor. ... gitGraph commit branch feature branch release checkout feature commit id: "A" commit id: "B" checkout main merge feature id: "M" checkout release cherry-pick id: "M"
Author   mermaid-js
🌐
LinuxBuz
linuxbuz.com › devops › cherry-pick-a-commit-in-git
Cherry Pick a Commit in Git – A Definitive Guide - LinuxBuz
September 13, 2024 - Git cherry-pick is a command that lets you copy a commit from one branch to another. Unlike merging or rebasing, which deal with multiple commits, cherry-picking focuses on individual commits.
🌐
Gitcheatsheet
gitcheatsheet.org › how-to › git-cherry-pick
Cherry-pick commits | Git Cheat Sheet
git cherry-pick abc123 Merges only the commit "abc123" into the current branch. Additionally, you can use the "-x" option to automatically append a "cherry picked from commit" to the commit message, specifying which commit has been picked.
🌐
Substack
gitbetter.substack.com › git better › how to use git cherry-pick effectively
How to use git cherry-pick effectively
January 23, 2023 - So when you are cherry-picking a merge commit you have to specify whether you need to cherry-pick parent-A branch or the parent-B branch. A - B - C - E - F (branch A) \ / G - H - I (branch B) In this above case, E is the merge commit.
🌐
Sysxplore
blog.sysxplore.com › what is git cherry-pick? how to use it🍒
What is Git cherry-pick? How to use it🍒
November 6, 2025 - Git cherry-picking refers to the process of selecting individual commits from any branch and applying them to the current HEAD branch. Unlike git rebase and git merge, which involve taking all the commits in an entire branch, cherry-pick allows ...
🌐
Better Programming
betterprogramming.pub › git-cherry-pick-merge-only-the-selected-commits-in-git-cli-and-gui-99259de728e3
Git Cherry-pick: Merge Only the Selected Commits in Git CLI and GUI | by Muge Evren Bulut | Better Programming
February 1, 2022 - Cherry-pick in Git means to choose a commit from one branch and apply it to another. This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch.