首页 > 解决方案 > How do I get BASE / REMOTE / LOCAL files without launching a mergetool GUI?

问题描述

I'm not quite sure even how to ask this question... but perhaps:

I am in a conflict state. I want to use null-op or /bin/bash as my merge tool.

That is, I want git to create the (REMOTE, LOCAL, BASE, etc) files, and then drop me back to a prompt for manual diff / merging. And then I want to tell git when I'm done.

What is the mergetool I want, and how do I specify it?

Note: This is a related question, but 1) it conflates rebasing (I'm not rebasing), and 2) there is no satisfying answer, e.g. "choose any mergetool and force-quit it." :P

标签: linuxgitcommand-line-interfacemergetool

解决方案


git mergetool是一个 shell 脚本(/bin/sh;/bin/bash 可以运行它,如果你只有 bash 而不是普通的旧 sh)。它:

  1. 从索引中提取三个文件(.BASE= 阶段 1 条目,.LOCAL= 阶段 2 条目,.REMOTE= 阶段 3 条目)。第四个文件用作对合并工具的检查——如果您要手动进行合并,则不需要此文件。
  2. 使用第二个 shell 脚本运行您选择的合并工具。
  3. 根据工具及其退出状态,询问您是否合并成功,或使用退出状态来决定合并是否成功。如果您说是,它将git add在合并文件上运行。
  4. 删除它在步骤 1 中创建的文件。

对于所有未合并的文件,它会循环执行此操作。

您的工作是修改那个 shell 脚本,以便它提取三个文件并保留它们,即执行(大部分)步骤 1,然后根本不执行其余步骤。只需找到脚本——它就在其中$(git --exec-path)/git-mergetool——并以另一个名称复制它,例如,git-extract-unmerged修改它以按照你想要的方式运行,然后运行git extract-unmerged,你就会得到你想要的那些.BASE、、.LOCAL.REMOTE文件。

(或者您可以设置merge.conflictStylediff3并且不打扰上述所有内容,因为工作树文件具有您需要的所有信息。这就是我所做的。)


推荐阅读