I am trying to learn how to use git cherry pick, I read the manual pages that git
returns by doing git cherry-pick --help
but that did not seem to help. I will try and explain the problem below. I have two branches master
and other
.
On branch master
The commit history is
0x2 Second commit from master branch
0x1 Initial commit
And the only file in the repository that I am tracking readme
has the following contents
Some text
On branch other
The commit history is
0x5 CHECKPOINT, going to cherry-pick onto master
0x4 second commit from branch other
0x3 first commit from other branch:
0x2 Second commit from master branch
0x1 Initial commit
And the contents of the readme
file are
Some text.
Adding some text from other branch. Adding some more text.
Going to cherry-pick this commit.
The working directory is clean on both branches with no untracked changes. From this point on when I switch to the master branch and merge with git merge other
the merge happens gracefully with no merge conflicts. But when I try git cherry-pick 0x5
there is a merge conflict, I get the following output from git
error: could not apply 0x5... CHECKPOINT, going to cherry-pick onto master
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
And the readme
file has the following contents
<<<<<<< HEAD
Some text
=======
Some text.
Adding some text from other branch. Adding some more text.
Going to cherry-pick this commit.
>>>>>>> 0x5... CHECKPOINT, going to cherry-pick onto master
Why is there this merge conflict? I am trying to understand why it occurs. Shouldn't cherry-pick
ing be the same as trying to make all the edits made on the commit that is to be cherry-pick
ed yourself and then commiting that change onto the branch (master
in this case)?
Also when exactly is there a merge conflict in git
? I seem to get them at weird times. Is this implementation dependent (for example dependent on the algorithm used to merge)?
Thank you!