I've merged 2 branches and conflicts appeared, I would need some hints where it starts where it ends, etc. I've replaced the code with some faked data to make it easier to read and talk about.
<<<<<<< HEAD
aaaaaa
||||||| merged common ancestors
<<<<<<< Temporary merge branch 1
bbbbbb
=======
cccccc
>>>>>>> mybranch
dddddd
<<<<<<< HEAD
eeeeee
||||||| merged common ancestors
ffffff
||||||| merged common ancestors
gggggg
=======
>>>>>>> Temporary merge branch 2
=======
hhhhhh
>>>>>>> mybranch
Here's an article about git's diff3 merge style. It points out that it's hard to tell whether lines are being added or deleted in this style.
I suggest you refine your question if you are looking for specific information. It's hard to tell what you're asking.
What you're seeing in this example (with
Temporary merge branch
markers) is the result of diff3 with a criss-cross merge conflict. I'll explain this with a sequence of definitions.Definitions
Example criss-cross merge conflict scenario
A criss-cross merge occurs whenever two branches merge into each other at different points in time.
Consider this sequence of events:
m0
exists as origin/masterfeature-A
with one commitA
m1
gets committed to master by someone elsefeature-B
that builds onA
origin/master
(m1
) intofeature-B
. It conflicts, and I resolve it. The merge commit isB0
.B1
.feature-A
is ready to ship, so someone merges it intomaster
. It conflicts. They resolve it, but their resolution differs from the resolution inB0
. The merge commit ism2
.feature-B
is ready to ship, so someone merges it intomaster
. git tries to determine the merge base, butm1
andA
both qualify equally as merge bases. git mergesm1
andA
in a temporary merge branch, which results in a conflict. We see diff3 output in the merged common ancestors section, similar to the OP's question.Reading the output
With diff3 off, this merge conflict would look simply like this:
First, with all the extra markers, you'll want to determine what the actual conflicting lines are, so you can differentiate it from the diff3 common ancestor output.
aaaaaahhhhhh, that's a little better. ;-)
In the case where two conflict resolutions are conflicting,
aaaaaa
andhhhhhh
are the two resolutions.Next, examine the content of the merged common ancestor.
With this particular merge history, there were more than 2 merge bases, which required multiple temporary merge branches which were then merged together. The result when there are many merge bases and conflicts can get pretty hairy and difficult to read. Some say don't bother, just turn off diff3 for these situations.
Also be aware that git internally may decide to use different merge strategies to auto-resolve conflicts, so the output can be hard to understand. Make sense out of it if you can, but know that it was not intended for human consumption. In this case, a conflict occurred when merging
mybranch
intoTemporary merge branch 1
betweenbbbbbb
andcccccc
. Linedddddd
had no conflicts between the temporary merge branches. Then a separate conflict occurred when mergingTemporary merge branch 2
intoHEAD
, with multiple common ancestors.HEAD
had resolved the conflict by mergingffffff
andgggggg
aseeeeee
, butTemporary merge branch 2
resolved that same conflict by deleting (or moving) the line (thus no lines between======
andTemporary merge branch 2
.How do you resolve a conflict like this? While technical analysis may be possible, your safest option is usually to go back and review the history in all the involved branches around the conflict, and manually craft a resolution based on your understanding.
Avoiding all this
These conflicts are the worst, but there are some behaviors that will help prevent them.
Avoid criss-cross merges. In the example above,
feature-B
mergedorigin/master
asB0
. It's possible that this merge to stay up-to-date with master wasn't necessary (though sometimes it is). Iforigin/master
was never merged intofeature-B
, there would have been no merge criss-cross, andm3
would have been a normal conflict withA
as the only merge base.m2
andB0
had different conflict resolutions. If they had resolved the conflict identically,m3
would have been a clean merge. Realize though that this is a simple criss-cross merge that ought to have had the same resolution. Other situations may rightly have different resolutions. Things get more complicated when there are more than 2 merge bases and multiple commits between the merge points. That said, if you are knowingly inconsistent with conflict resolutions in criss-cross situations, expect headaches later.