如何解决与“git mergetool”的多个冲突而不必关闭文件之间的编辑器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/585844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:11:59  来源:igfitidea点击:

How resolve multiple conflicts with "git mergetool" without having to close the editor between files?

gitdiffmergetool

提问by Rob Wilkerson

I've found git mergetoolto 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:

我发现git mergetool是一个在视觉上合并差异的方便实用程序,但我要处理的方式似乎真的很奇怪。本质上,当报告冲突时,我的流程如下所示:

  1. Execute a git mergetool
  2. At the prompt, hit Enterto launch my diff tool (Meld or FileMerge, depending on which computer)
  3. Resolve the conflicts
  4. Save the changes
  5. Close the diff tool
  1. 执行一个git mergetool
  2. 在提示下,按 Enter启动我的差异工具(Meld 或 FileMerge,具体取决于哪台计算机)
  3. 解决冲突
  4. 保存更改
  5. 关闭差异工具

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.

如果我有不止一个冲突,冲洗,重复。是的,这就是我为合并中的每个冲突打开和关闭我的差异查看器一次。因为它是从命令行启动的,所以关闭它是我所知道的告诉 git mergetool 我已经解决了这个特定冲突并且它可以继续下一个的唯一方法。

Surely there's a better way, but I have no idea. Li'l help, please? This process seems crazy inefficient.

当然有更好的方法,但我不知道。请你帮忙好吗?这个过程似乎非常低效。

采纳答案by VonC

At first glance, it does not seem possible to reuse an external diff tool session.

乍一看,似乎不可能重用外部差异工具会话。

The git-mergetooldocumentationclearly states:

git-mergetool文件明确规定:

If the custom merge tool correctly indicates the success of a merge resolution with its exit code, then the configuration variable mergetool.<tool>.trustExitCodecan be set to true.
Otherwise, git-mergetoolwill prompt the user to indicate the success of the resolution after the custom tool has exited.

如果自定义合并工具通过其退出代码正确指示合并解析成功,则mergetool.<tool>.trustExitCode可以将配置变量设置为 true。
否则git-mergetool会在自定义工具退出后提示用户提示解析成功。

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.

所以需要退出代码(或者说diff工具退出后用户的验证),暗示用户先关闭外部diff工具。

That seems a great incentive to reduce the number of conflicts on each merge/rebase one attempts ;) (whatever the VCScs tool used)

这似乎是减少每次合并/变基一次尝试的冲突数量的一个很好的动力;)(无论使用什么 VCScs 工具)

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 closingthe external diff tool...

注意:
另外两个 git 外部 diff 工具设置(“在 Windows 上为 Git 设置 diff 和合并工具”和“使用 Git 设置 SourceGear DiffMerge”)在不关闭外部 diff 工具时并没有给更多希望...

回答by Brian Phillips

If your mergetool of choice supports opening files in an existing instance, you can specify the command in your git config:

如果您选择的合并工具支持在现有实例中打开文件,您可以在 git 配置中指定命令:

% git config mergetool.whatever_you_want.cmd 'exec /path/to/merge/tool $LOCAL $MERGED $REMOTE'
% git config merge.tool whatever_you_want

git mergetoolwill 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).

git mergetool然后将执行您的自定义命令,然后提示您文件是否已成功合并(而不是查看退出代码)。

An example I just hacked together for vimdiff:

我刚刚为 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!

这工作得很好,我可以自己开始使用它!

回答by CB Bailey

The problem for mergetool is that it deliberately uses a command line interface to initiate a merge session and then waits for the invoked command to return to determine when the user driven merge has completed.

mergetool 的问题在于它故意使用命令行界面来启动合并会话,然后等待调用的命令返回以确定用户驱动的合并何时完成。

Most merge tools don't provide a command line mechanism for starting a merge session in an already running process with a way for determining when the resolution has been completed and whether successful or not.

大多数合并工具不提供用于在已经运行的进程中启动合并会话的命令行机制,以及用于确定解析何时完成以及是否成功的方法。

It is conceivable that some merge tools could provide this functionality through a separate wrapper command and some sort of IPC, but it would be exceedingly tool specific and difficult to implement in the generic mergetool program.

可以想象,一些合并工具可以通过单独的包装器命令和某种 IPC 来提供此功能,但是这将非常特定于工具并且难以在通用合并工具程序中实现。