如何解决与“git mergetool”的多个冲突 无需在文件之间关闭编辑器?
我发现 git mergetool 是一个方便的实用程序,可以直观地合并差异,但我的处理方式似乎很奇怪。 本质上,当报告冲突时,我的流程如下所示:
- 执行 git mergetool
- 在提示符下,按 Enter 启动我的 diff 工具(Meld 或 FileMerge,具体取决于哪台计算机) )
- 解决冲突
- 保存更改
- 关闭差异工具
如果我有多个冲突,请冲洗,重复。 是的,这就是我为合并中的每个冲突打开和关闭一次差异查看器。 由于它是从命令行启动的,因此关闭它是我所知道的告诉 git mergetool 我已经解决了这个特定冲突并且可以继续处理下一个冲突的唯一方法。
当然有更好的方法,但我不知道。 请李帮忙好吗? 这个过程看起来效率极低。
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:
- Execute a git mergetool
- At the prompt, hit Enter to launch my diff tool (Meld or FileMerge, depending on which computer)
- Resolve the conflicts
- Save the changes
- Close the diff tool
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
乍一看,似乎不可能重用外部差异工具会话。
git-mergetool
文档< /a> 明确指出:因此需要退出代码(或在 diff 工具退出后对用户进行验证),这意味着用户首先关闭外部 diff 工具。
这似乎是减少每次合并/变基一次尝试时的冲突数量的巨大动力;)(无论使用什么 VCScs 工具)
注意:
另外两个 git 外部 diff 工具设置 ("在 Windows 上为 Git 设置差异和合并工具" 和 "使用 Git 设置 SourceGear DiffMerge") 在不关闭时不会给予更多希望 外部差异工具...
At first glance, it does not seem possible to reuse an external diff tool session.
The
git-mergetool
documentation clearly states: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...
如果您选择的合并工具支持在现有实例中打开文件,您可以在 git 配置中指定命令:
git mergetool
然后将执行您的自定义命令,然后提示您文件是否合并成功(代替查看退出代码)。我刚刚为 vimdiff 编写的一个例子:
这个效果很好,我自己可以开始使用它!
If your mergetool of choice supports opening files in an existing instance, you can specify the command in your git config:
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:
This works well enough, I may start using it myself!
mergetool 的问题在于,它故意使用命令行界面来启动合并会话,然后等待调用的命令返回以确定用户驱动的合并何时完成。
大多数合并工具不提供命令行机制来在已运行的进程中启动合并会话,并提供确定解析何时完成以及是否成功的方法。
可以想象,一些合并工具可以通过单独的包装器命令和某种 IPC 来提供此功能,但这将是极其特定于工具的,并且难以在通用合并工具程序中实现。
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.
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.
我一直在寻找这个答案非常非常非常长的时间。 现在我终于得到了这个简单的解决方案(令人惊讶):
meld 。
这将在版本控制视图中打开融合。
通过这种方式,您可以解决选项卡中的冲突,并在每次单击“标记为已解决”按钮时将其标记为已解决。
I've been looking for this answer for a very, very, very long time. Now I finally get this simple solution (amazingly):
meld .
This will open meld in version control view.
In this way, you can solve conflicts in tabs and mark them as resolved whenever you click the "Marked as resolved" button.