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
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With