On Mon, 3 Apr 2017 21:07:02 +0200 Pablo Rodríguez <oi...@web.de> wrote:
[...] > My question is simple: what causes a merge conflict? > > I mean, changes in different files are merged fine, since the most > updated version of each is merged. > > I thought the same happened with different lines (the latter modified > line is kept in the merged file), but I can’t say for sure after > experiencing the merge conflicts. > > Could you confirm whether lines are merged independently or whether > there is always a conflict when one tries to pull a modified file from > remote in a file that was also modified after latest push in local? It's a bit trickier. To begin with, in most cases of simple merging, Git uses the so-called 3-way merging, where it first figures out the point where both sides of the merge diverged, and compares _differences_ introduced by the sides since that point. Now the crucial idea to understand about conflict detection is that of the "context". When examining differences, Git takes into account several lines above and below the detected change, and judging from this context, it tries to understand whether a particular change introduced by one side of the merge happens in the same place as another change introduced by the other side of the merge. If these changes happen in different contexts, they are considered non-conflicting. As to lines, yes, Git considers changes to happen line-wise. Another interesting aspect is that one can turn on ignoring of whitespace changes, so that two lines which only differ in the amount of whitespace characters would be considered the same. This is useful for certain textual formats where _some_ spacing is insignificant -- such as TeX/LaTeX, Markdown etc (see the `git diff` manual page about the "-b", "-w" and "--ignore-space-at-eol" command-line options). -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.