threads / discuss / 24762

Conflict markers in mergetool $LOCAL ?

Subject: Conflict markers in mergetool $LOCAL ?

## tl;dr

8 messages between Aug 17, 2010 and Aug 18, 2010.

replies: 7people: 4as markdown or json

Seth House· Aug 17, 2010, 04:34 UTC · lore

Hello. I'm a recent convert from Mercurial; I'm enjoying the transition and am feeling pretty comfortable with most of Git. However, I haven't used mergetool much yet because it puts conflict markers in the "ours" pane -- but (even after a chat in #git on IRC) I'm not sure if that is intended behavior or if my setup is broken. I would appreciate some guidance.

For small conflicts, I like the conflict markers and simply editing the conflicted file with Vim. For files with lots of conflicts I would like to use vimdiff but I wouldn't expect the conflict markers to appear there -- it's redundant information in a 3-way merge.

Is there a better Git Way (TM) that I'm missing? Is my Git setup borked somehow?

I have the following in my ~/.gitconfig and a stock Git installation on Arch Linux.

[merge]
    tool = vimdiff
[mergetool "vimdiff"]
    cmd = vimdiff
    trustExitCode = true
David Aguilar· Aug 17, 2010, 09:30 UTC · re: Seth House · lore

Re: Conflict markers in mergetool $LOCAL ?

On Tue, Aug 17, 2010 at 04:34:20AM +0000, Seth House wrote:
Show 14 quoted lines
> [...]
> For small conflicts, I like the conflict markers and simply editing the
> conflicted file with Vim. For files with lots of conflicts I would like to use
> vimdiff but I wouldn't expect the conflict markers to appear there -- it's
> redundant information in a 3-way merge.
> 
> Is there a better Git Way (TM) that I'm missing? Is my Git setup borked
> somehow?
> 
> I have the following in my ~/.gitconfig and a stock Git installation on Arch
> Linux.
> 
> [merge]
>     tool = vimdiff
What happens if you remove this section?:
> [mergetool "vimdiff"]
>     cmd = vimdiff
>     trustExitCode = true

mergetool has built-in support for vimdiff. You shouldn't need to define mergetool.vimdiff.cmd.

Does that change anything?
-- 
	David
David Aguilar· Aug 17, 2010, 09:32 UTC · re: David Aguilar · lore

Re: Conflict markers in mergetool $LOCAL ?

On Tue, Aug 17, 2010 at 02:30:23AM -0700, David Aguilar wrote:
Show 25 quoted lines
> On Tue, Aug 17, 2010 at 04:34:20AM +0000, Seth House wrote:
> > [...]
> > For small conflicts, I like the conflict markers and simply editing the
> > conflicted file with Vim. For files with lots of conflicts I would like to use
> > vimdiff but I wouldn't expect the conflict markers to appear there -- it's
> > redundant information in a 3-way merge.
> > 
> > Is there a better Git Way (TM) that I'm missing? Is my Git setup borked
> > somehow?
> > 
> > I have the following in my ~/.gitconfig and a stock Git installation on Arch
> > Linux.
> > 
> > [merge]
> >     tool = vimdiff
> 
> 
> What happens if you remove this section?:
> 
> > [mergetool "vimdiff"]
> >     cmd = vimdiff
> >     trustExitCode = true
> 
> mergetool has built-in support for vimdiff.
> You shouldn't need to define mergetool.vimdiff.cmd.

Typo, ^^^^^^^^^^^^^^^^^^^^^ Should say: mergetool.cmd.vimdiff

-- 
	David
Seth House· Aug 17, 2010, 17:08 UTC · re: David Aguilar · lore

Re: Conflict markers in mergetool $LOCAL ?

David Aguilar <davvid <at> gmail.com> writes:
> What happens if you remove this section?:
Same result. The conflict markers are still there:
http://i.imgur.com/d1vp1.png
Jacob Helwig· Aug 17, 2010, 18:00 UTC · re: Seth House · lore

Re: Conflict markers in mergetool $LOCAL ?

That actually looks exactly like it should.  The order of the windows that vimdiff uses is (IIRC): ours, on-disk file, theirs.
"Seth House" <seth@eseth.com> wrote:
Show 11 quoted lines
>David Aguilar <davvid <at> gmail.com> writes:
>> What happens if you remove this section?:
>
>Same result. The conflict markers are still there:
>
>http://i.imgur.com/d1vp1.png
>
>--
>To unsubscribe from this list: send the line "unsubscribe git" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
Seth House· Aug 17, 2010, 21:04 UTC · re: Jacob Helwig · lore

Re: Conflict markers in mergetool $LOCAL ?

Jacob Helwig <jacob.helwig <at> gmail.com> writes:
> That actually looks exactly like it should.  The order of the windows
> that vimdiff uses is (IIRC): ours, on-disk file, theirs.

Hm, you’re right. I just found the git-mergetool--lib script on my system and it opens vimdiff with $LOCAL $MERGED $REMOTE. Thank you, that opened my eyes enough to clarify my question:

The conflict markers don't seem very useful in the context of a merge tool. I would prefer to see two windows in vimdiff with each side of the conflict, respectively. Something like:

vimdiff $MERGED-left-hand-conflicts $MERGED-right-hand-conflicts

Is that possible with Git -- or does anyone know of external tools to help with such a workflow?

Charles Bailey· Aug 17, 2010, 21:24 UTC · re: Seth House · lore

Re: Conflict markers in mergetool $LOCAL ?

On 17/08/2010 22:04, Seth House wrote:
Show 16 quoted lines
> Jacob Helwig<jacob.helwig<at>  gmail.com>  writes:
>> That actually looks exactly like it should.  The order of the windows
>> that vimdiff uses is (IIRC): ours, on-disk file, theirs.
>
> Hm, you’re right. I just found the git-mergetool--lib script on my
> system and it opens vimdiff with $LOCAL $MERGED $REMOTE. Thank you, that
> opened my eyes enough to clarify my question:
>
> The conflict markers don't seem very useful in the context of a merge
> tool. I would prefer to see two windows in vimdiff with each side of the
> conflict, respectively. Something like:
>
> vimdiff $MERGED-left-hand-conflicts $MERGED-right-hand-conflicts
>
> Is that possible with Git -- or does anyone know of external tools to
> help with such a workflow?

I think that your problem is mainly with vimdiff, not with mergetool. Or perhaps the way they interact. Although I'm a heavy vim user I don't really get on with vimdiff as a merge tool. Most 3-way merge tools use BASE, LOCAL and REMOTE to allow a good semi-automatic conflict resolution to be performed. vimdiff is used by mergetool as a two-way diff tool with an extra edit pane; it's not quite the same thing.

The conflict markers have been but into the target file by merge before mergetool even starts and mergetool considers the target file to be an output only.

I personally have used and would recommend kdiff3 and the Perforce visual merge tool with git. Can I suggest you try a different mergetool to see if you works better for you?

Charles.
Seth House· Aug 18, 2010, 03:22 UTC · re: Charles Bailey · lore

Re: Conflict markers in mergetool $LOCAL ?

Charles Bailey <charles <at> hashpling.org> writes:
> Most 3-way merge tools use BASE, LOCAL and REMOTE

That is how Mercurial invokes vimdiff, except it also uses a wrapper shell script in order to tell vimdiff where to save the final edit.

That said, you're right that vimdiff doesn't do the "good semi-automatic conflict resolution" that you spoke of.

> I personally have used and would recommend kdiff3

I spent some time playing with kdiff3 today. Thanks for the recommendation. I now understand why a merge tool that has native support for comparing all four file versions ($BASE, $LOCAL, $REMOTE, and $MERGED) is vastly more powerful than tools that don't (vimdiff, Meld) -- and I wish that bit of information would make it into more diff-tool comparisons discussions online.

So, back to my OP, most of the time I deal with tiny conflicts. I wanted a quick way to look at *only* the conflicts without having to do the search-next-search-next dance with my editor -- which is something that vimdiff can do very well. In case anyone stumbles on to this thread looking for something similar, I settled on the script below.

Thanks for your help/advice, David, Jacob, and Charles!

#!/bin/sh # Use vimdiff to quickly go through Git merge conflicts. # # Save your changes to the LOCAL file. MERGED will be updated if # vimdiff exits cleanly. Use :cq to abort. # # Put the following in your ~/.gitconfig # # [mergetool "vimdiffconflicts"] # cmd = unmerge.sh $BASE $LOCAL $REMOTE $MERGED # trustExitCode = true

if [[ -z $@ || $# != "4" ]] ; then
    echo -e "Usage: $0 \$BASE \$LOCAL \$REMOTE \$MERGED"
    exit 1
fi

BASE=$1 LOCAL=$2 REMOTE=$3 MERGED=$4

sed -e '/<<<<<<</,/=======/d' -e '/>>>>>>>/d' $MERGED > $LOCAL sed -e '/=======/,/>>>>>>>/d' -e '/<<<<<<</d' $MERGED > $REMOTE

vim -f -d $BASE $LOCAL $REMOTE \
    -c ':diffoff' -c ':set scrollbind' -c 'wincmd l'
EC=$?

# Overwrite $MERGED [[ $EC == "0" ]] && cat $LOCAL > $MERGED

exit $EC

← back to recent threads