loading...

Discussion on: How To Avoid Merge Conflicts

Collapse
jessekphillips profile image
Jesse Phillips

I totally understand that merges can get complicated, and rerere looks like a good tip; what I don't understand is how a diff is different from a merge conflict. Am merge conflict is generally handled by a diff tool.

Collapse
samuyi profile image
Samuyi Author

a diff shows you the differences between revisions of the same file. It helps you compare files. Merge conflict happens when you try to merge versions of the same file and git can't automatically pick which version to go with based on it's three way merge algorithm. Therefore it's needs some kind of human intervention to resolve the problem.

Collapse
jessekphillips profile image
Jesse Phillips

But how does a human intervene, I use a diff. Diffing two files also does not change the fact that a conflict exists and any action to combine changes of two files is a merge. And the article was about avoiding them.

Thread Thread
samuyi profile image
Samuyi Author

The diff helps to spot conflicts right before they happen. You can then do a

$ git merge -s ours branch2

to use your changes.
or

$ git merge -s theirs branch2

to use their changes.

With this there is no conflict since you have inspected the changes and told git how to resolve the conflict. In essence you have told git what to do before any conflicts occur, since you saw them before hand.

Thread Thread
jessekphillips profile image
Jesse Phillips

From my perspective the conflict still exists. The difference is that the tool did not tell you about it, you identified it yourself and instructed git how to resolve it.

Thread Thread
jessekphillips profile image
Jesse Phillips

I also would not generally recommend those commands for resolution during a merge multiple conflicts can occur and which side you desire changes based on the conflict, and this ignores a common desire to accurately merge the two changes.