Edit: I added some Information I thought to be unnecessary, but is not. I have two branches, A and B. After making three commits in A that changes file.c I want to cherry-pick them into B, there is also a file.h which was changed in A~1
> git cherry-pick A~2
Success
> git cherry-pick A~1
error: could not apply 81e0723...
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'
> git status
You are currently cherry-picking commit 81e0723.
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: some/unrelated/file.txt
both modified: file.c
Now when looking at some/unrelated/file.txt it contains the changes to file.h somewhere right in the middle. So this looks like a bug in git. So I will now undo the changes some/unrelated/file.txt manually and add them to file.h.
It's possible the cherry-pick is changing a function that had also been changed earlier in
B
's history, so the changes specifically inA~1
are to lines that already looked different from what's in theB
version and git can't see where inB
the cherry-pick's changes apply.It's also possible that the context git finds for the changes has evil twins lying in wait elsewhere in the code (say, multiple lines with nothing but standalone closing braces), and other changes have put the real corresponding original in your code far enough from where it was in
A~1^
that the hunt for the context inB
finds something else instead. The manual suggests aborting the cherry-pick and retrying withgit cherry-pick -Xpatience
might be enough to avoid trouble with those, that spends an ordinarily-unreasonable amount of time trying to avoid getting lost in a sea of braces. Here's probably a good place to start if you want details on how that really works.