5

I read an article about three-way merges (diff3). It gives an example about how is detects a conflict. The example is :

A=[1,4,5,2,3,6]
O=[1,2,3,4,5,6] <<< Origin
B=[1,2,4,5,3,6]

In the first time it computes the diff between O-A and after O-B:

A=[1,4,5,2,3,   ,6]
O=[1,   ,2,3,4,5,6] 

and

O=[1,2,3,4,5, ,6] 
B=[1,2, ,4,5,3,6]

After it makes diff3 parse:

A=[1,4,5,2,   3    ,6]
O=[1,   ,2, 3,4,5  ,6] <<< Origin
B=[1,   ,2, 4,5,3  ,6]

And after it detects the conflict :

1
4
5
2
<<<<<<<<<A
3
|||||||O
3
4
5
=======
4
5
3
>>>>>>B
6

Following this method to detect the conflict, i try a simple example : initially i have the document :

a;
b;

i make an updates user 1 update "a;", to "a=0;" user 2 update "b;", to "b=0;" I obtain this result :

xx
<<<<<<< A
int a=0;
int b;
||||||| O
int a;
int b;
=======
int a;
int b=0;
>>>

When i merge these two documents i have a conflict even if i don't change at the same position (a and b are not at the same position)! some one can explain me why i have this conflict ?

Mehdi
  • 2,160
  • 6
  • 36
  • 53
  • Are the entries for a; b; in the document on the same line? – Schleis May 14 '13 at 14:45
  • NO there are not at the same line ! – Mehdi May 14 '13 at 14:47
  • if the whole document is only 3 lines long, then it's probably just not enough context for diff to properly recognize the non-conflict case. and if diff is confused, it's a conflict ;) – Nevik Rehnel May 14 '13 at 14:53
  • @NevikRehnel, i don't think it is the size of the document. Diff does not work with the size of the doc, if there is two lines or 1000 it's the same. I explain how diff3 detect the conflict and in its method there is not a size of doc. – Mehdi May 14 '13 at 14:58
  • 3
    This question is flawed in several ways: 1) it doesn't link to the article, 2) it doesn't explain how this is related to git, 3) it doesn't clearly explain what the numbers mean (I assume they refer to line numbers), 4) it doesn't give steps to reproduce the problem. Please edit and you will have a greater chance of receiving a useful answer. – Adam Spiers May 18 '13 at 09:44
  • 1
    @AdamSpiers found [this pdf about diff3](http://www.cis.upenn.edu/~bcpierce/papers/diff3-short.pdf) that has those numbers, maybe it will help? –  May 25 '13 at 06:13

1 Answers1

1

This question is very similar to this one, and the answer also is: That's because each diff hunk does not only consist of the literal difference but also of some lines of context that are required to locate the difference in a file that has some lines added / removed and thus the hunk offset changes. A difference in the context is also a conflict because depending on what patch you would apply first you're changing the context for the other patch.

Community
  • 1
  • 1
sschuberth
  • 28,386
  • 6
  • 101
  • 146