什么是默认的 git diff 工具(和 merge 工具)?
我在哪里(以及如何)找到它?
我从来没有明确地为 git difftool(也不是 mergetool)设置任何配置,
所以 git config --get difftool
什么也没显示。
git 文档说( https://git-scm.com/docs/git-difftool ):
If the configuration variable
diff.tool
is not set,git difftool
will pick a suitable default.
我怎样才能知道它选择了哪一个?
“合适”的算法如何工作?
让我分享一下我试图通过我的 git 找出当前选择的差异工具的原因:
我在执行
git diff
时遇到了一些奇怪的差异结果(我怀疑是 BOM 处理问题)。我想询问供应商(例如
p4merge
),但不确定它是
p4merge
、 vimdiff
还是其他任何东西。我希望可能有一个像
git difftool --current
这样的命令。
最佳答案
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
function 中找到该进程。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,则您没有在 MacOS 上不正确的 GUI。然后它简单地遍历它们并选择第一个它找到的用于使用
type
的可执行文件。更新
I've met some weird diff result when I execute git diff(I suspect BOM handling issue). I'd like to question the vendor(e.g., p4merge) about it, but not sure if it is p4merge, vimdiff or anything else.
如果您遇到的
git diff
问题是 git diff
而不是 git difftool
。我认为 git difftool
的作用有些困惑,所以这里有一个快速概述。git diff
不使用 git-difftool 。 git difftool
不会为 git diff
选择差异工具。 git diff
有自己的内部差异实现。它还可以通过提供 --ext-diff
来使用外部 diff 程序,例如 GNU diff。当您运行
git difftool
时,它会选择一个外部 diff 程序并使用三个环境变量运行它:$LOCAL、$REMOTE 和 $MERGED。 $LOCAL 是文件旧版本的路径,$REMOTE 是新版本的路径,$MERGED 是文件名以便可以显示。就是这样。它与 git diff
无关。我们可以通过将自定义 difftools 添加到 .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 - 什么是默认的 git diff 工具(和 merge 工具)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63985751/