Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: commit is a merge but no -m option was given

Tags:

git

when I do git cherry-pick, I got this error, how can I solve it?

$ git cherry-pick  XXXXXXXXXXXXX                                                                                                                                          
error: commit XXXXXXXXXXXXX is a merge but no -m option was given.
fatal: cherry-pick failed
$ git cherry-pick
    -m, --mainline <n>    parent number
$ git cherry-pick -m 1234 XXXXXXXXXXXXX
$ error: commit XXXXXXXXXXXXX does not have parent 1234
fatal: cherry-pick failed
like image 524
Sato Avatar asked Jan 25 '17 01:01

Sato


2 Answers

I've had this same error when using git revert to revert a merge (feature branch which turned out to be bad). The -m is a bit confusing. Its not looking for a message. I think it just wants to know how far back from the given commit you want to revert (how many commits to revert)

Most of the time it's just 1. I.e. you only want to go back to the commit before your merge (the commit hash I'm providing). So the solution is:

git revert -m 1 <git_hash_for_merge>
like image 56
robjwilkins Avatar answered Nov 16 '22 09:11

robjwilkins


I think the help/man page explains pretty clearly why you need the -m parameter and the error message pretty clearly specifies that you need it:

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

like image 2
jbu Avatar answered Nov 16 '22 10:11

jbu