Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cherry pick shows no -m option was given error

I have two branch master and development

I need to get some commit id from development branch in master branch so I do it by cherry-pick but it shows me some error

$> git cherry-pick cf0d52b

error: Commit cf0d52b900f990300c3aa17936ddbae1476d461a is a merge but no -m option was given.
fatal: cherry-pick failed

I am not getting this error, why this error comes and how will I get rid of this.

like image 967
Akash Jain Avatar asked May 02 '16 06:05

Akash Jain


People also ask

How do you reset cherry-pick?

6 Answers. Show activity on this post. A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit. Stash your current changes so you can reapply them after resetting the commit.

Is a merge but no option was given Cherrypick failed?

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.

How do you undo a unsuccessful cherry-pick?

Try also with '--quit' option, which allows you to abort the current operation and further clear the sequencer state. --quit Forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or revert. --abort Cancel the operation and return to the pre-sequence state.


2 Answers

You are trying to cherry-pick a merge. A merge is build up from at several parents. You have to supply the parent id to the merge.

You have to supply any of the followings:

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


How to find out what are the commit parents?

Use the git show command to view the commit parents and then you can choose the parent index or the SHA-1

enter image description here

like image 143
CodeWizard Avatar answered Oct 23 '22 13:10

CodeWizard


This option specifies the parent number (starting from 1)

Up until Git 2.13 (Q2 2017), that number could be 0! (which is incorrect)

See commit b16a991 (15 Mar 2017) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 9c96637, 17 Mar 2017)

cherry-pick: detect bogus arguments to --mainline

The cherry-pick and revert commands use OPT_INTEGER() to parse --mainline. The stock parser is smart enough to reject non-numeric nonsense, but it doesn't know that parent counting starts at 1.

Worse, the value "0" is indistinguishable from the unset case, so a user who assumes the counting is 0-based will get a confusing message:

$ git cherry-pick -m 0 $merge
  error: commit ... is a merge but no -m option was given.

The correct diagnosis is that "-m 0" does not refer to the first parent ("-m 1" does).

like image 9
VonC Avatar answered Oct 23 '22 15:10

VonC