Search code examples
c#gitcherry-pick

Git auto-merging removed some information while cherry-picking


At work, I had to include a commit from a remote branch to my local branch.

Because I did not want to merge yet, I cherry-picked the remote commit to my local branch.

While cherry-picking, Git performed an auto-merge whithout prompting me for a conflict.

I then realized that some vital lines of code from the remote were missing from the resulting commit.

I put the case here:

https://github.com/apicoding/SimplePrj

1. My 'Initial commit' in master is missing the mandatory 'Print()' method implementation.

2. The 'Print()' method is defined in 'Ready to merge' commit in remote.

3. After cherry-picking/auto-merge 'Ready to merge' commit to master, the 'Print()' method is still undefined.

Do you have an explanation why git cherry-pick can choose to remove some information whitout raising a conflict and asking the user to choose ?


Solution

  • When you're cherrypicking, you're taking the commit you cherrypick into your branch, so if you cherrypicked the Ready to merge commit from remote then only the comment //ready to merge went to your branch (which is the only change that commit has).

    If you wanted to take all the changes from remote you should've merged the branch, not cherrypicked that single commit.

    Hope it helps!