{"thread":{"id":"24762","subject":"Conflict markers in mergetool $LOCAL ?","startedAt":"2010-08-17T04:34:20Z","lastAt":"2010-08-18T03:22:58Z","messageCount":8,"participants":["Seth House","David Aguilar","Jacob Helwig","Charles Bailey"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"148223","messageId":"loom.20100817T054731-955@post.gmane.org","threadId":"24762","inReplyTo":null,"subject":"Conflict markers in mergetool $LOCAL ?","fromName":"Seth House","fromEmail":"seth@eseth.com","sentAt":"2010-08-17T04:34:20Z","receivedAt":"2010-08-17T04:34:20Z","isPatch":false,"sender":{"key":"seth@eseth.com","avatar":"https://avatars.githubusercontent.com/u/91293?v=4"},"body":"Hello. I'm a recent convert from Mercurial; I'm enjoying the transition and am\nfeeling pretty comfortable with most of Git. However, I haven't used mergetool\nmuch yet because it puts conflict markers in the \"ours\" pane -- but (even after\na chat in #git on IRC) I'm not sure if that is intended behavior or if my setup\nis broken. I would appreciate some guidance.\n\nFor small conflicts, I like the conflict markers and simply editing the\nconflicted file with Vim. For files with lots of conflicts I would like to use\nvimdiff but I wouldn't expect the conflict markers to appear there -- it's\nredundant information in a 3-way merge.\n\nIs there a better Git Way (TM) that I'm missing? Is my Git setup borked\nsomehow?\n\nI have the following in my ~/.gitconfig and a stock Git installation on Arch\nLinux.\n\n[merge]\n    tool = vimdiff\n\n[mergetool \"vimdiff\"]\n    cmd = vimdiff\n    trustExitCode = true\n"},{"id":"148263","messageId":"20100817093008.GA26357@gmail.com","threadId":"24762","inReplyTo":"loom.20100817T054731-955@post.gmane.org","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-08-17T09:30:23Z","receivedAt":"2010-08-17T09:30:23Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Tue, Aug 17, 2010 at 04:34:20AM +0000, Seth House wrote:\n> [...]\n> For small conflicts, I like the conflict markers and simply editing the\n> conflicted file with Vim. For files with lots of conflicts I would like to use\n> vimdiff but I wouldn't expect the conflict markers to appear there -- it's\n> redundant information in a 3-way merge.\n> \n> Is there a better Git Way (TM) that I'm missing? Is my Git setup borked\n> somehow?\n> \n> I have the following in my ~/.gitconfig and a stock Git installation on Arch\n> Linux.\n> \n> [merge]\n>     tool = vimdiff\n\n\nWhat happens if you remove this section?:\n\n> [mergetool \"vimdiff\"]\n>     cmd = vimdiff\n>     trustExitCode = true\n\nmergetool has built-in support for vimdiff.\nYou shouldn't need to define mergetool.vimdiff.cmd.\n\nDoes that change anything?\n\n-- \n\n\tDavid\n"},{"id":"148264","messageId":"20100817093246.GB26357@gmail.com","threadId":"24762","inReplyTo":"20100817093008.GA26357@gmail.com","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2010-08-17T09:32:47Z","receivedAt":"2010-08-17T09:32:47Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Tue, Aug 17, 2010 at 02:30:23AM -0700, David Aguilar wrote:\n> On Tue, Aug 17, 2010 at 04:34:20AM +0000, Seth House wrote:\n> > [...]\n> > For small conflicts, I like the conflict markers and simply editing the\n> > conflicted file with Vim. For files with lots of conflicts I would like to use\n> > vimdiff but I wouldn't expect the conflict markers to appear there -- it's\n> > redundant information in a 3-way merge.\n> > \n> > Is there a better Git Way (TM) that I'm missing? Is my Git setup borked\n> > somehow?\n> > \n> > I have the following in my ~/.gitconfig and a stock Git installation on Arch\n> > Linux.\n> > \n> > [merge]\n> >     tool = vimdiff\n> \n> \n> What happens if you remove this section?:\n> \n> > [mergetool \"vimdiff\"]\n> >     cmd = vimdiff\n> >     trustExitCode = true\n> \n> mergetool has built-in support for vimdiff.\n> You shouldn't need to define mergetool.vimdiff.cmd.\n\nTypo,                          ^^^^^^^^^^^^^^^^^^^^^\nShould say:                    mergetool.cmd.vimdiff\n\n-- \n\n\tDavid\n"},{"id":"148293","messageId":"loom.20100817T185804-167@post.gmane.org","threadId":"24762","inReplyTo":"20100817093008.GA26357@gmail.com","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"Seth House","fromEmail":"seth@eseth.com","sentAt":"2010-08-17T17:08:44Z","receivedAt":"2010-08-17T17:08:44Z","isPatch":false,"sender":{"key":"seth@eseth.com","avatar":"https://avatars.githubusercontent.com/u/91293?v=4"},"body":"David Aguilar <davvid <at> gmail.com> writes:\n> What happens if you remove this section?:\n\nSame result. The conflict markers are still there:\n\nhttp://i.imgur.com/d1vp1.png\n"},{"id":"148299","messageId":"f595ee73-b1a3-4797-bf55-20c0f1b309e0@email.android.com","threadId":"24762","inReplyTo":"loom.20100817T185804-167@post.gmane.org","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"Jacob Helwig","fromEmail":"jacob.helwig@gmail.com","sentAt":"2010-08-17T18:00:14Z","receivedAt":"2010-08-17T18:00:14Z","isPatch":false,"sender":{"key":"jacob.helwig@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14557?v=4"},"body":"That actually looks exactly like it should.  The order of the windows that vimdiff uses is (IIRC): ours, on-disk file, theirs.\n\n\"Seth House\" <seth@eseth.com> wrote:\n\n>David Aguilar <davvid <at> gmail.com> writes:\n>> What happens if you remove this section?:\n>\n>Same result. The conflict markers are still there:\n>\n>http://i.imgur.com/d1vp1.png\n>\n>--\n>To unsubscribe from this list: send the line \"unsubscribe git\" in\n>the body of a message to majordomo@vger.kernel.org\n>More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"148306","messageId":"loom.20100817T230158-934@post.gmane.org","threadId":"24762","inReplyTo":"f595ee73-b1a3-4797-bf55-20c0f1b309e0@email.android.com","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"Seth House","fromEmail":"seth@eseth.com","sentAt":"2010-08-17T21:04:20Z","receivedAt":"2010-08-17T21:04:20Z","isPatch":false,"sender":{"key":"seth@eseth.com","avatar":"https://avatars.githubusercontent.com/u/91293?v=4"},"body":"Jacob Helwig <jacob.helwig <at> gmail.com> writes:\n> That actually looks exactly like it should.  The order of the windows\n> that vimdiff uses is (IIRC): ours, on-disk file, theirs.\n\nHm, you’re right. I just found the git-mergetool--lib script on my\nsystem and it opens vimdiff with $LOCAL $MERGED $REMOTE. Thank you, that\nopened my eyes enough to clarify my question:\n\nThe conflict markers don't seem very useful in the context of a merge\ntool. I would prefer to see two windows in vimdiff with each side of the\nconflict, respectively. Something like:\n\nvimdiff $MERGED-left-hand-conflicts $MERGED-right-hand-conflicts\n\nIs that possible with Git -- or does anyone know of external tools to\nhelp with such a workflow?\n"},{"id":"148309","messageId":"4C6AFE09.5020302@hashpling.org","threadId":"24762","inReplyTo":"loom.20100817T230158-934@post.gmane.org","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2010-08-17T21:24:25Z","receivedAt":"2010-08-17T21:24:25Z","isPatch":false,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"On 17/08/2010 22:04, Seth House wrote:\n> Jacob Helwig<jacob.helwig<at>  gmail.com>  writes:\n>> That actually looks exactly like it should.  The order of the windows\n>> that vimdiff uses is (IIRC): ours, on-disk file, theirs.\n>\n> Hm, you’re right. I just found the git-mergetool--lib script on my\n> system and it opens vimdiff with $LOCAL $MERGED $REMOTE. Thank you, that\n> opened my eyes enough to clarify my question:\n>\n> The conflict markers don't seem very useful in the context of a merge\n> tool. I would prefer to see two windows in vimdiff with each side of the\n> conflict, respectively. Something like:\n>\n> vimdiff $MERGED-left-hand-conflicts $MERGED-right-hand-conflicts\n>\n> Is that possible with Git -- or does anyone know of external tools to\n> help with such a workflow?\n\nI think that your problem is mainly with vimdiff, not with mergetool. Or \nperhaps the way they interact. Although I'm a heavy vim user I don't \nreally get on with vimdiff as a merge tool. Most 3-way merge tools use \nBASE, LOCAL and REMOTE to allow a good semi-automatic conflict \nresolution to be performed. vimdiff is used by mergetool as a two-way \ndiff tool with an extra edit pane; it's not quite the same thing.\n\nThe conflict markers have been but into the target file by merge before \nmergetool even starts and mergetool considers the target file to be an \noutput only.\n\nI personally have used and would recommend kdiff3 and the Perforce \nvisual merge tool with git. Can I suggest you try a different mergetool \nto see if you works better for you?\n\nCharles.\n"},{"id":"148336","messageId":"loom.20100818T052242-649@post.gmane.org","threadId":"24762","inReplyTo":"4C6AFE09.5020302@hashpling.org","subject":"Re: Conflict markers in mergetool $LOCAL ?","fromName":"Seth House","fromEmail":"seth@eseth.com","sentAt":"2010-08-18T03:22:58Z","receivedAt":"2010-08-18T03:22:58Z","isPatch":false,"sender":{"key":"seth@eseth.com","avatar":"https://avatars.githubusercontent.com/u/91293?v=4"},"body":"Charles Bailey <charles <at> hashpling.org> writes:\n> Most 3-way merge tools use BASE, LOCAL and REMOTE\n\nThat is how Mercurial invokes vimdiff, except it also uses a wrapper\nshell script in order to tell vimdiff where to save the final edit.\n\nThat said, you're right that vimdiff doesn't do the \"good semi-automatic\nconflict resolution\" that you spoke of.\n\n> I personally have used and would recommend kdiff3\n\nI spent some time playing with kdiff3 today. Thanks for the\nrecommendation. I now understand why a merge tool that has native\nsupport for comparing all four file versions ($BASE, $LOCAL, $REMOTE,\nand $MERGED) is vastly more powerful than tools that don't (vimdiff,\nMeld) -- and I wish that bit of information would make it into more\ndiff-tool comparisons discussions online.\n\nSo, back to my OP, most of the time I deal with tiny conflicts. I wanted\na quick way to look at *only* the conflicts without having to do the\nsearch-next-search-next dance with my editor -- which is something that\nvimdiff can do very well. In case anyone stumbles on to this thread\nlooking for something similar, I settled on the script below.\n\nThanks for your help/advice, David, Jacob, and Charles!\n\n#!/bin/sh\n# Use vimdiff to quickly go through Git merge conflicts.\n# \n# Save your changes to the LOCAL file. MERGED will be updated if\n# vimdiff exits cleanly. Use :cq to abort.\n# \n# Put the following in your ~/.gitconfig\n#\n# [mergetool \"vimdiffconflicts\"]\n#     cmd = unmerge.sh $BASE $LOCAL $REMOTE $MERGED\n#     trustExitCode = true\n\nif [[ -z $@ || $# != \"4\" ]] ; then\n    echo -e \"Usage: $0 \\$BASE \\$LOCAL \\$REMOTE \\$MERGED\"\n    exit 1\nfi\n\nBASE=$1\nLOCAL=$2\nREMOTE=$3\nMERGED=$4\n\nsed -e '/<<<<<<</,/=======/d' -e '/>>>>>>>/d' $MERGED > $LOCAL\nsed -e '/=======/,/>>>>>>>/d' -e '/<<<<<<</d' $MERGED > $REMOTE\n\nvim -f -d $BASE $LOCAL $REMOTE \\\n    -c ':diffoff' -c ':set scrollbind' -c 'wincmd l'\n\nEC=$?\n\n# Overwrite $MERGED\n[[ $EC == \"0\" ]] && cat $LOCAL > $MERGED\n\nexit $EC\n"}]}