Use Diff Conflict Style 3
Table of Contents
Please, just turn on diff style 3. Thank me later. I do not know the historical reason this setting is not the default, but if you ask me to help you with some crazy merge conflict, I am going to immediately ask you to configure this setting.
Context
When dealing with conflicts, merge or otherwise, one of the options for your VCS is to modify the files with "conflict markers". These are those crazy alligators that infect the code when receiving conflicts.
long fib(long n) { <<<<<<< HEAD long sol = 1; for (; n > 0; n--) { sol *= n; } return sol; ======= if (n <= 0) { return 1; } else { return n * fib(n - 1); } >>>>>>> MERGE_HEAD }
While this may correctly point out the differences between the two branches, this output says nothing of the shared context from whence they came.
diff3
Instead, by using diff3
, the base context is provided along with the
conflicting differences:
long fib(long n) { <<<<<<< HEAD long sol = 1; for (; n > 0; n--) { sol *= n; } return sol; ||||||| Parent return -1; ======= if (n <= 0) { return 1; } else { return n * fib(n - 1); } >>>>>>> MERGE_HEAD }
Now, in this contrived example, we can tell that two different developers
implemented a version of Fibonacci function, replacing the stub of -1
.
Notice, if they each individually arrived at the same solution, it would still result in a conflict.
Using this conflict resolution style in Git
Zealous Diff3
More options to consider
Julia Evans has an excellent post summarizing popular configuration options for Git which you should check out.