默认的 git diff 工具(和合并工具)是什么?
What is the default git diff tool(and merge tool)?
默认的 git 差异工具(和合并工具)是什么?
我在哪里(以及如何)找到它?
我从未明确地为 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.
我怎样才能知道它选择了哪一个?
“suitable”的算法如何工作?
让我分享一下我试图通过 git:
找出当前选择的 diff 工具的原因
我在执行 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,则您没有 GUI,这在 MacOS 上是不正确的。
然后它简单地遍历它们并选择第一个找到可执行文件以供使用 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
的 diff 工具。 git diff
有自己的内部差异实现。它还可以通过提供 --ext-diff
.
使用外部差异程序,如 GNU diff
当您 运行 git difftool
时,它会选择一个外部差异程序并 运行 使用三个环境变量对其进行设置:$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 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.
我怎样才能知道它选择了哪一个?
“suitable”的算法如何工作?
让我分享一下我试图通过 git:
找出当前选择的 diff 工具的原因
我在执行 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,则您没有 GUI,这在 MacOS 上是不正确的。
然后它简单地遍历它们并选择第一个找到可执行文件以供使用 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
的 diff 工具。 git diff
有自己的内部差异实现。它还可以通过提供 --ext-diff
.
当您 运行 git difftool
时,它会选择一个外部差异程序并 运行 使用三个环境变量对其进行设置:$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 也不应该。