I've found git mergetool to be a handy utility for merging diffs visually, but the way I'm going about it seems really wonky. Essentially, my process looks like this when conflicts are reported:
If I have more than one conflict, rinse, repeat. Yep, that's me opening and closing my diff viewer once for each conflict in the merge. Since it's launched from the command line, closing it is the only way I know of to tell git mergetool that I've resolved this particular conflict and that it can move on to the next.
Surely there's a better way, but I have no idea. Li'l help, please? This process seems crazy inefficient.
Concepts for resolving Git conflictsREMOTE - the head for files(s) from a remote location that you are trying to merge into your LOCAL branch. BASE - the common ancestor(s) of LOCAL and REMOTE . MERGED - the tag / HEAD object after the merge - this is saved as a new commit.
At first glance, it does not seem possible to reuse an external diff tool session.
The git-mergetool
documentation clearly states:
If the custom merge tool correctly indicates the success of a merge resolution with its exit code, then the configuration variable
mergetool.<tool>.trustExitCode
can be set to true.
Otherwise,git-mergetool
will prompt the user to indicate the success of the resolution after the custom tool has exited.
So the exit code (or the validation of the user after the exit of the diff tool) is needed, implying that the user first close the external diff tool.
That seems a great incentive to reduce the number of conflicts on each merge/rebase one attempts ;) (whatever the VCScs tool used)
Note:
Two other git external diff tools settings ("Setting up diff and merge tools for Git on Windows" and "Setting up SourceGear DiffMerge with Git") do not give more hopes when it come to not closing the external diff tool...
If your mergetool of choice supports opening files in an existing instance, you can specify the command in your git config:
% git config mergetool.whatever_you_want.cmd 'exec /path/to/merge/tool $LOCAL $MERGED $REMOTE' % git config merge.tool whatever_you_want
git mergetool
will then execute your custom command and then prompt you as to whether the file was merged successfully (in lieu of looking at an exit code).
An example I just hacked together for vimdiff:
% git config mergetool.persistent.cmd 'gvim --remote-tab-silent "+set buftype=nowrite" "$PWD/$BASE" && sleep 1; gvim --remote-send ":split $PWD/$REMOTE<CR>:set buftype=nowrite<CR>:vertical diffsplit $PWD/$MERGED<CR>:vertical diffsplit $PWD/$LOCAL<CR>:set buftype=nowrite<CR><C-W>l"'
This works well enough, I may start using it myself!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With