git difftool
命令会告诉你它将要尝试做什么。
$ git difftool
This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
kompare emerge vimdiff
Viewing (1/1): 'this'
Launch 'emerge' [Y/n]?
我们可以在
guess_merge_tool
函数中找到该过程。
guess_merge_tool () {
list_merge_tool_candidates
cat >&2 <<-EOF
This message is displayed because '$TOOL_MODE.tool' is not configured.
See 'git ${TOOL_MODE}tool --tool-help' or 'git help config' for more details.
'git ${TOOL_MODE}tool' will now attempt to use one of the following tools:
$tools
EOF
# Loop over each candidate and stop when a valid merge tool is found.
IFS=' '
for tool in $tools
do
is_available "$tool" && echo "$tool" && return 0
done
list_merge_tool_candidates
函数设置了 $tools
列表。它假设如果未设置 DISPLAY,就没有 GUI,但这在 MacOS 上是不正确的。
然后它简单地循环遍历这些工具,并使用type
命令选择找到的第一个可执行文件。
更新
我执行git diff时遇到了一些奇怪的差异结果(我怀疑是BOM处理问题)。我想向供应商(例如p4merge)询问,
但不确定是否是p4merge、vimdiff或其他原因。
如果您遇到的是与 git diff
相关的问题,则不是 git difftool
的问题。我认为有一些关于 git difftool
功能的混淆,
所以这里简要介绍一下。
git diff
不使用 git-difftool。git difftool
不会选择用于 git diff
的差异工具。
git diff
有自己的内部差异实现。它也可以使用外部差异程序(例如 GNU diff),只需提供 --ext-diff
。
当您运行 git difftool
时,它会选择一个外部差异程序,并使用三个环境变量:$LOCAL、$REMOTE 和 $MERGED。$LOCAL 是文件旧版本的路径,
$REMOTE 是文件新版本的路径,$MERGED 是文件名,以便进行显示。大体如此。它与 git diff
没有关系。
我们可以通过将自定义差异工具添加到 .gitconfig 中来查看 git difftool
的操作:
[difftool "echo"]
cmd = echo "LOCAL: $LOCAL, REMOTE: $REMOTE, MERGED: $MERGED"
[difftool "less"]
cmd = less "$LOCAL" "$REMOTE"
git difftool -t echo
将显示环境变量。git difftool -t less
将在less
翻页器中查看旧版本和新版本文件的内容。
如果您在使用git diff
时遇到问题,git difftool
、p4merge和vimdiff都与之无关。
git difftool --tool-help
。 - Schwern--tool-help
只显示所有可能的 _候选项_,而不是当前的。 - ALittleDiff