Conflict markers in mergetool $LOCAL ?
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
Quoted 6 lines · Seth House
[...]
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.
Quoted 8 lines
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?:
Quoted 3 lines
[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?
Signature · 1 line
David
Quoted 17 lines · David Aguilar
Quoted 6 lines · Seth House
[...]
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.Quoted 8 lines
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
Quoted 8 lines
What happens if you remove this section?:
Quoted 3 lines
[mergetool "vimdiff"]
cmd = vimdiff
trustExitCode = truemergetool has built-in support for vimdiff. You shouldn't need to define mergetool.vimdiff.cmd.
Typo, ^^^^^^^^^^^^^^^^^^^^^
Should say: mergetool.cmd.vimdiff
Signature · 1 line
David
Quoted 1 line · David Aguilar <davvid <at> gmail.com> writes:
What happens if you remove this section?:
Same result. The conflict markers are still there:
That actually looks exactly like it should. The order of the windows that vimdiff uses is (IIRC): ours, on-disk file, theirs.
Quoted 11 lines · Seth House
Quoted 1 line · David Aguilar <davvid <at> gmail.com> writes:
What happens if you remove this section?:
Same result. The conflict markers are still there:
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 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?
Quoted 8 lines · Seth House
Quoted 2 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:
Quoted 8 lines
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.
Quoted 1 line · 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.
Quoted 1 line
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 1fi
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