-2

I'm trying to cherry-pick a commit from CyanogenMod Github and having issue, here's more info:

DomQ
  • 4,184
  • 38
  • 37
Sid
  • 17
  • 1
  • 5

1 Answers1

1

When cherry-picking a merge commit, you need to specify the mainline. The documentation:

-m parent-number

--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.

Consider the following commit log:

   B - C
  /     \
A--D-E-F-G

Now, if you tell git to cherry-pick G, you are telling it: "Take the changes that commit G introduces". But that is ambiguous - in relation to commit C, G introduces changes made in D, E, and F. In relation to commit F, it introduces changes B and C.

To overcome this, you need to specify the mainline argument, which tells git whether C or F should be considered the mainline against which the comparison is done.

1615903
  • 32,635
  • 12
  • 70
  • 99
  • Thanks for the answer, what should I do now? Do the changes manually or there's more options? – Sid Dec 12 '16 at 06:27
  • 1
    You should specify the `-m` argument as my answer suggests. – 1615903 Dec 12 '16 at 06:27
  • can I cherry both commits which were merged in that commit? – Sid Dec 12 '16 at 06:44
  • I don't think you understand what cherry-picking a merge commit implies. You need to tell git if you want the changes that the commit introduces in relation to commit `54eac05` or commit `8159d23`. – 1615903 Dec 12 '16 at 06:54
  • @Sid Check the edits I made, see if it clears things up. – 1615903 Dec 12 '16 at 07:06
  • 1
    The help says "parent number" but your example has "C" and "F" as the parents, how do I convert to this parent number, is F = 1? – gakera Apr 21 '20 at 14:56
  • 1
    Doing `git show G` (where G is a merge commit) will display a line like this: `Merge: abc123 def456`. The `-m` parameter refers to the order of these commits. – 1615903 Apr 22 '20 at 06:04