I have a project with two branches:
D---E branch1
/
---A---C branch2
I want to apply commit E (but not D) on top of branch2.
I used git cherry-pick and git mergetool (with meld) for resolving conflicts. So far, so good.
However, suppose that the state of the file after commit C is
lineC1
<context C>
lineC2
and the change introduced by commit E is
-lineC1
+lineE1
<context E>
-lineC2
+lineE2
I would expect the result shown by default by the mergetool to be
lineE1
<context C>
lineE2
(i.e., lines E1 and E2 changed according to commit E but internal context kept from the current branch).
Instead, the mergetool (i.e., meld) by default shows:
lineC1
<context E>
lineC2
which really makes no sense.
How can I instruct git cherry-pick to keep the context from branch2 and only consider changes to the lines modified by commit E ?
There is generally no correct solution for merging, programs can only provide heuristic suggestions. If the suggestion is not what you need, you just need to edit it. I think meld should show you everything you need on the screen. And even if it does not you can use commands like git show <sha1>:<file>
to display every existing version of your file for copy pasting. After you have edited the middle column in meld git will accept it as it is, regardless of the changes you made.
You might also want to try git config --global --add merge.conflictstyle diff3
In the next cherry-pick (or merge) the result of the conflict will be formatted a bit differently and with some luck more suitable for your case.