0

I want to cherry-pick this commit id to another branch.

commit f0ca878ef7748975ee3110923310da6491dd9a23
Merge: 17eb265 4d712a1
Author: ravi<ravi@sysbiz.in>
Date:   Thu Dec 3 12:40:19 2015 +0530

    Merge branch 'master' of https://github.com/HexagonGlobal/hexgen into master

While doing cherry-pick, I am getting this error

D:\GitHub\sysbiz\src>git cherry-pick f0ca878ef7748975ee3110923310da6491dd9a23
error: Commit f0ca878ef7748975ee3110923310da6491dd9a23 is a merge but no -m option was given.
fatal: cherry-pick failed

Thanks in advance

vijay
  • 77
  • 1
  • 7
  • From the docs: *--mainline parent-number 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.* – Atri Jan 07 '16 at 06:23
  • 1
    Possible duplicate of [git cherry-pick says "...38c74d is a merge but no -m option was given"](http://stackoverflow.com/questions/9229301/git-cherry-pick-says-38c74d-is-a-merge-but-no-m-option-was-given) – Andrew C Jan 07 '16 at 07:08

2 Answers2

2

In order for Cherry-pick to know what changes to apply it needs to know not only the commit being picked but also the parent to compare to (because cherry-pick calculates differences between the commit being picked and its parent).

Now, in case of a "merge" commit, that commit has two parents, so you have to use the -m argument to specify one of those parents (the first or the second).

If you don't know what the two parents are, I suggest you try both -m 1 and -m 2, and see if I get the expected result.

See here.

Adi Levin
  • 4,858
  • 1
  • 12
  • 24
2

You are trying to merge a merge commit.

Merge commit has 2 parents so you need to specify which parent u wish to pick.

enter image description here

As you can see here C1 has 2 parents C2 & C3. You have to pass parent id to the cherry-pick to "tell" him which commit C2 or C3 to choose.

git cherry-pick -m 1 <sha-1>
CodeWizard
  • 92,491
  • 19
  • 110
  • 133