gitcherry-pick

Cherry pick shows "commit is a merge but no -m option was given" error


I have two branches, master and development.

I need to get some commit from the development branch into the master branch. 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 do not understand this error, why does this error come and how will I get rid of it?


Solution

  • 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