Samar Kr Mishra Samar Kr Mishra - 2 months ago 13
Git Question

GIT cherry-pick giving error

I am trying to cherry-pick one of the commit using the sha to my branch but its giving error.

Say I am on branch

x
, then I am running the command
git cherry-pick as560aad0138....
in my terminal.

The error I got is like this;

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

Answer

The answer is right there, in the error message.

From man git cherry-pick:

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