1

How exactly does git determine that there is a conflict between lines? What rules are followed to determine what types of differences constitute a conflict and which ones can be safely merged?

For a particular example, say we have two csv files. When would git conclude that two csv files that share records (i.e. rows) cannot be merged automatically?

For example, say both csv include the same common set of records, but one of them is adding entries, could this ever cause a conflict?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

2 Answers2

2

It depends on the tool used for diff. Normally diffs compare lines. If one line is changed on a revision and the same line is modified on another revision, if you try to merge them you'll have a conflict.

diff is based on solving the longest common subsequence problem.

diff does not know a line was modified. It knows a line (or various lines) was removed and another one (or more than one) was inserted between two identical parts of file.

revision A:

a b c
d e f
g h i

revision B:

a b c
d e a f
g h i

$ diff A B

will output that line d e f was removed and line d e a f was inserted on file B in comparison with file A between the identical lines a b c and g h i.

If file A is modified into C:

a b c
c
d e b f
g h i

the diff will output that the same line was removed, but lines c and d e b f were inserted.

Merging B and C, the conflict will not be only

d e a f
====
d e b f

but

d e a f
====
c
d e b f

So, in a short way, diff searches for identical blocks of lines. If files were modified between these blocks on both files (and the modification was not identical), there will be a conflict.

Jean Waghetti
  • 4,711
  • 1
  • 18
  • 28
0

You can actually use your own plugin to handle conflicts in git if you don't like the way it's handling your conflicts.

However, check out this page for more info: http://en.wikipedia.org/wiki/Merge_%28revision_control%29#Three-way_merge

user3270760
  • 1,444
  • 5
  • 23
  • 45
  • This allows you to use a tool to deal with conflicts *after* they have been deemed conflicts. It does not impact how Git automerges files. – Edward Thomson Sep 03 '14 at 20:13