{"thread":{"id":"39176","subject":"Inexplicable merge conflict produced when when lines next to each other are changed","startedAt":"2015-04-28T07:34:30Z","lastAt":"2015-04-29T02:35:10Z","messageCount":2,"participants":["Anuradha Dissanayake","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"260115","messageId":"loom.20150428T093059-405@post.gmane.org","threadId":"39176","inReplyTo":null,"subject":"Inexplicable merge conflict produced when when lines next to each other are changed","fromName":"Anuradha Dissanayake","fromEmail":"falconne@gmail.com","sentAt":"2015-04-28T07:34:30Z","receivedAt":"2015-04-28T07:34:30Z","isPatch":false,"sender":{"key":"falconne@gmail.com","avatar":null},"body":"I posted this question to StackOverflow a while ago but no one answered \nit so I thought I'd try here.\n\nLet's say I have a file with this content in master:\n\n_____\nLine 1\nLine 2\nLine 3\nLine 4 \n_____\n\nNow say I create and checkout a new branch called Test. In this branch I \nchange the file to this:\n\n_____\nLine 1\nLine 2\nLine 3 Modified\nLine 4 \n_____\n\nand I commit this and switch back to master. In master I change the file \nto:\n\n_____\nLine 1\nLine 2\nLine 3\nLine 4 Modified \n_____\n\nand I commit. Now if I merge branch Test into master, I get a conflict.\n\nWhy can't git auto resolve this, as those are two entirely independent \nlines? If I tell git to edit conflicts using BeyondCompare as the \ndifftool, BeyondCompare autoresolves this without even telling the user, \nsince this isn't a real conflict (other merge tools we use at our \ncompany do so also). Is there a way to get git to autoresolve these? \nI've tried the recursive and resolve merge strategies but neither do it.\n\nIt's an issue in our company because there are certain files where \nmultiple developers change lines in close proximity and this causes many \nunnecessary conflicts when they pull.\n"},{"id":"260156","messageId":"20150429023509.GB438@peff.net","threadId":"39176","inReplyTo":"loom.20150428T093059-405@post.gmane.org","subject":"Re: Inexplicable merge conflict produced when when lines next to each other are changed","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-04-29T02:35:10Z","receivedAt":"2015-04-29T02:35:10Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Apr 28, 2015 at 07:34:30AM +0000, Anuradha Dissanayake wrote:\n\n> Let's say I have a file with this content in master:\n> \n> _____\n> Line 1\n> Line 2\n> Line 3\n> Line 4 \n> _____\n> \n> Now say I create and checkout a new branch called Test. In this branch I \n> change the file to this:\n> \n> _____\n> Line 1\n> Line 2\n> Line 3 Modified\n> Line 4 \n> _____\n> \n> and I commit this and switch back to master. In master I change the file \n> to:\n> \n> _____\n> Line 1\n> Line 2\n> Line 3\n> Line 4 Modified \n> _____\n> \n> and I commit. Now if I merge branch Test into master, I get a conflict.\n> \n> Why can't git auto resolve this, as those are two entirely independent \n> lines?\n\nThe content-level merge in git looks for overlapping diff hunks. It does\nhave a \"level\" setting which will try with varying degrees of effort to\nshrink the conflict section, but I do not think there is a setting that\nwill resolve this cleanly. Short of teaching a new level to the libxdiff\nmerge code, I think the best you can do is to specify your own\ncontent-level merge driver for these files, and feed the data to another\nprogram which does the merge differently (whether it is simply more\naggressive at finding conflicts, or it might even know something about\nthe semantics of the file). See the \"three-way merge\" section in \"git\nhelp attributes\".\n\n> If I tell git to edit conflicts using BeyondCompare as the \n> difftool, BeyondCompare autoresolves this without even telling the user, \n> since this isn't a real conflict (other merge tools we use at our \n> company do so also). Is there a way to get git to autoresolve these? \n> I've tried the recursive and resolve merge strategies but neither do it.\n\nI don't think a change of merge strategy will help; they all end up\ndoing the content-level merge with the same libxdiff code.\n\n-Peff\n\nPS I'm answering your \"how to\" questions directly without considering\n   whether what you are asking for is a good idea. But you may want\n   to think about whether there is a case that matches the above pattern\n   that you would _not_ want to auto-resolve (i.e., even though there is\n   not strictly a textual conflict, there is a good chance there is a\n   semantic conflict because the lines are so close together).\n"}]}