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

发布于 2024-07-14 02:48:15 字数 447 浏览 6 评论 0原文

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

  1. 执行 git mergetool
  2. 在提示符下,按 Enter 启动我的 diff 工具(Meld 或 FileMerge,具体取决于哪台计算机) )
  3. 解决冲突
  4. 保存更改
  5. 关闭差异工具

如果我有多个冲突,请冲洗,重复。 是的,这就是我为合并中的每个冲突打开和关闭一次差异查看器。 由于它是从命令行启动的,因此关闭它是我所知道的告诉 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:

  1. Execute a git mergetool
  2. At the prompt, hit Enter to launch my diff tool (Meld or FileMerge, depending on which computer)
  3. Resolve the conflicts
  4. Save the changes
  5. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紫竹語嫣☆ 2024-07-21 02:48:15

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

git-mergetool 文档< /a> 明确指出:

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

因此需要退出代码(或在 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:

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...

往事风中埋 2024-07-21 02:48:15

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

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

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

我刚刚为 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"'

这个效果很好,我自己可以开始使用它!

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!

沙与沫 2024-07-21 02:48:15

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.

丢了幸福的猪 2024-07-21 02:48:15

我一直在寻找这个答案非常非常非常长的时间。 现在我终于得到了这个简单的解决方案(令人惊讶):

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文