9

运行时git mergetool,我想让 git 根据文件扩展名选择使用的合并工具。我怎样才能做到这一点?

这里提出了一个类似的问题:Git: configure patterns for difftool and mergetool ,答案是编写自定义合并驱动程序。但是,似乎这将在 上执行git merge,而我希望在 上选择合并工具git mergetool

似乎必须有某种方法可以用 .gitattributes 指定它,但我似乎无法弄清楚如何。有什么建议吗?

4

1 回答 1

7

一种解决方案(因为我的旧答案不适合mergetool)是设置为mergetool包装脚本

git config --global merge.tool customMergeTool
git config --global mergetool.customMergeTool.cmd 'customMergeTool.sh \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'

该包装脚本customMergeTool.sh将:

  • 检查是什么$BASE(特别是它的文件扩展名)
  • 基于该扩展调用适当的合并工具
  • 返回那个的退出状态mergetool

例如,这是OP elsevers提出的脚本:merge-wrapper.

于 2014-04-27T08:32:35.107 回答