How do I make gvimdiff opened by git mergetool open all files at once in tabs?

烈酒焚心 提交于 2019-12-24 09:35:30

问题


Normally git -c merge.tool=gvimdiff mergetool opens files to be merged on by one, in batch mode:

Normal merge conflict for '...':
  {local}: modified file
  {remote}: modified file
4 files to edit
... seems unchanged.
Was the merge successful? [y/n] n
merge of ... failed
Continue merging other unresolved paths (y/n) ? y
Normal merge conflict for '...':
  {local}: modified file
  {remote}: modified file
4 files to edit
modules ... seems unchanged.
Was the merge successful? [y/n] n
merge of modules ... failed
Continue merging other unresolved paths (y/n) ? n

How do I make it open all files at one, with tabs (like in gvim -p file1 file2) that contain the four pane arrangement for each file to be merged?


回答1:


git mergetool flow is designed to resolve conflicts in one file a time. Hence what you are asking for cannot be done in a clean way. However it is possible to create a custom mergetool, that will accumulate input from git mergetool in a single gvim window. The hack that this "solution" inevitably has to contain is that it must make the git mergetool flow believe that the custom mergetool has successfully merged the file, even though it just has opened the file in gvim. This is necessary so that the git mergetool flow proceeds to the next file without asking any questions. As a result, if you exit gvim without making any changes, git will still think that all conflicts have been resolved.

A draft version of such a custom mergetool (that opens files in different gvim windows, rather than in tabs) follows:

.gitconfig:

[mergetool "mygvimdiff"]
    cmd=/path/to/mygvimdiff "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
    trustExitCode=true

mygvimdiff:

#!/bin/bash

gvim -d -c "wincmd J" "$@"

# wait till gvim loads the temporary files before
# the git mergetool script deletes them
sleep 1

exit 0

Usage:

git mergetool -t mygvimdiff


来源:https://stackoverflow.com/questions/39259116/how-do-i-make-gvimdiff-opened-by-git-mergetool-open-all-files-at-once-in-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!