From: Seth House <hidden> Date: 2016-06-15 22:49:19
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
From: David Aguilar <hidden> Date: 2016-06-15 22:49:20
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
From: David Aguilar <hidden> Date: 2016-06-15 22:49:20
On Tue, Aug 17, 2010 at 02:30:23AM -0700, David Aguilar wrote:
On Tue, Aug 17, 2010 at 04:34:20AM +0000, Seth House wrote:
quoted
[...]
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
From: Jacob Helwig <hidden> Date: 2016-06-15 22:49:20
That actually looks exactly like it should. The order of the windows that vimdiff uses is (IIRC): ours, on-disk file, theirs.
"Seth House" [off-list ref] wrote:
From: Seth House <hidden> Date: 2016-06-15 22:49:20
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?
From: Charles Bailey <hidden> Date: 2016-06-15 22:49:20
On 17/08/2010 22:04, Seth House wrote:
Jacob Helwig<jacob.helwig<at> gmail.com> writes:
quoted
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.
From: Seth House <hidden> Date: 2016-06-15 22:49:20
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