3

Sometimes I get a bit disappointed with the results of a merge, git seems to not be able to solve simple conflicts automatically, so I thought there must be something that I'm missing, wrong setup or maybe there's a way to configure git to be more "aggressive" on conflicts resolution.

As an example, I'm adding this pic of my merge tool (P4Merge) with a conflict:

enter image description here

Bigger version here.

The file on the left modified two of the original (center) lines. The file on the right simply added a line between the two original lines.

They are completely independent changes, but because they are somehow together git throws a conflict.

It's easy to imagine a case where this would be a real conflict, but most of the time I think it would generate a compilation error that I'd prefer to fix instead of having merge conflicts.

I configured my merge tool to ignore line ending and all white space differences, and I have autocrlf = true, but maybe git is not ignoring white space differences when merging, and dumb conflicts like this appear. Is there a way to tweak how git handles conflict resolution?

3 Answers 3

1

It's easy to imagine a case where this would be a real conflict

You're right. Whatever change you made to the two original lines seems likely to need to be made to the line added between them.

<<<<<<<<<<<<< if ( g->tag == mark || g->tag == error ) { |||||||||||||| if ( tag == mark || tag == error ) { ============== if ( tag == mark || tag == release || tag == error ) { >>>>>>>>>>>>>> 

I'm suspicious of a tool that will auto-merge those, even if it's the right thing 99% of the time otherwise.

You could replay a long history of merges and compare performance, showing where your automerge produces different results than ordinary automerge. That shouldn't be too hard, save off the conflicted files in one pass and two-diff the collection afterwards at a guess.

Sign up to request clarification or add additional context in comments.

Comments

1

I don't think there are any systems that basically ignore conflicts (though svn will leave the conflicted file with both changes in it if you don't resolve the conflict when you merge, so you have a file that has diff markers in it)

Given you want to resolve conflicts afterwards, is it possible to configure git to do the same - ie ignore conflicts.

I'd say it's not the thing you really want to do, conflicts should be resolved immediately as you never know that the code will raise a compilation error, some changes won't if you ignore them. Best to fix them at merge time when you can see both sides.

4 Comments

I'm sorry but I think I wasn't clear, I don't want it to ignore conflicts, I want it to automatically resolve this conflict. See, in this particular case it can resolve it by simply doing nothing - because there is no conflict happening in the same line -, and this case happens a lot.
Maybe you want to try Fossil instead. Bear in mind merge algorithms are stupid, they do not know if this conflict can be auto-merged or not because it depends on contextual information that you can see, but a computer cannot possibly understand. Imagine if I gave you 3 lines of merged Welsh, you'd be unable to tell if they were valid or not and so unable to merge them without assistance. This is the same problem for the computer.
There could be a tool that would use the compiler to check if its automatic dumb merge generated compilable code. It doesn't solve the problem of having compilable conflicts solved wrongly, though. What Fossil has different that could help?
@Roberto Fossil's main benefit is automatic merging, which syncs with the upstream more readily - so you don't have such out of date local branches which is where the merge issues comes from - merging is generally easy at first, but the longer you leave a branch merging becomes progressively harder as it diverges from the trunk. There's no magic bullet for merging, no matter what anyone says. (well, there is - you can lock, edit and commit but this isn't the best workflow for teams)
0

As I see you have modification of the same text hunk in two different ways. This is what conflict is. You could try to use git mergetool -y -t mymagicmergetool and use magic conflict resolution tool to resolve all conflicts automatically.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.