Git (2.22.0) difftool 不再通过 git diff 如果 diff.tool 未设置

Git (2.22.0) difftool no longer passes through to git diff if diff.tool is unset

根据@VonC 在 Git 2.22.0(2019-06-08 发布)中 中的回答,对 git difftool 命令进行了一些更改,说明其如何配置确定。

但是,除非我在这里遗漏了什么,否则此版本中似乎引入了功能回归。在以前的版本中,包括 2.21.0,可以在没有任何配置或 CLI 选项的情况下使用 git difftool,在这种情况下它会传递给 git diff.

现在在 Git 2.22.0 中,如果我使用 git difftool 而不配置 diff.toolmerge.tool,我会收到以下消息:

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

有什么方法可以绕过这个错误并返回到传递给 git diff 的旧行为,还是我必须直接调用 git diff

编辑: 根据 Jeff King 的 mailing list reply, the new behavior is intentional. However at the top of the git-difftool documentation,它说:

git difftool is a frontend to git diff and accepts the same options and arguments. See git-diff[1].

现在不是这样了吗?

TLDR;新错误消息“This message is displayed because 'diff.tool' is not configured.”可能是实际的错误修复,不是新错误。


我刚刚试过了......没有收到任何错误消息(当使用 没有 参数时)。

vonc@vonvb:~/git/cplgit/linux$ ./set_git 2.22.0
git set to v2.22.0
vonc@vonvb:~/git/cplgit/linux$ git version
git version 2.22.0

vonc@vonvb:~/git/cplgit/linux$ git config -l|grep -i tool

vonc@vonvb:~/git/cplgit/linux$ git difftool

此外,此错误消息已在 commit 5338a6a, Jan. 2013, Git v1.8.2-rc0 中引入。
我确实提到了 commit 05fb872 from Git 2.22,它使用 ${GIT_MERGETOOL_GUI}.
我的机器上没有设置该环境变量,我没有收到任何错误消息。
检查你自己的 git config 和环境变量。

我确实在 Git 2.22 中看到错误消息:

vonc@vonvb:~/gits/src/git$ git difftool --no-index color.c color.h

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:
meld opendiff kdiff3 tkdiff xxdiff kompare gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare smerge emerge vimdiff

Viewing (1/1): 'color.c'
Launch 'bc' [Y/n]? 
The diff tool bc is not available as 'bcompare'
fatal: external diff died, stopping at color.c

对于 Git 2.21.0,它默认为常规 git diff:

vonc@vonvb:~/git/cplgit/linux$ ./set_git 2.21.0
git set to v2.21.0
vonc@vonvb:~/git/cplgit/linux$ git version
git version 2.21.0
vonc@vonvb:~/git/cplgit/linux$ cdgg
vonc@vonvb:~/gits/src/git$ git difftool --no-index color.c color.h
diff --git a/color.c b/color.h
index ebb222ec33..98894d6a17 100644

来自OP Git mailing list thread

Denton Liu pinpoints the original commit 287ab28 (16 Feb 2019) by Jeff King (peff).
(由 Junio C Hamano -- gitster -- in commit 12e5bdd 合并,2019 年 3 月 7 日)

diff: reuse diff setup for --no-index case

When "--no-index" is in effect (or implied by the arguments), git-diff jumps early to a special code path to perform that diff.
This means we miss out on some settings like enabling --ext-diff and --textconv by default.

Jeff King replies:

I don't know much about how git-difftool works, but it looks like it sets GIT_EXTERNAL_DIFF=git-difftool--helper.

Prior to 287ab28bfa, we would not have respected any external diff command when running git-diff. But after it, we do.

In the case that the user has not provided --no-index, then this all works as I guess difftool is meant to: it runs the helper and says "hey, you have not configured this".

It seems like the behavior of the above command prior to 287ab28bfa was not intentional.
It would run git-diff, expecting it to trigger the helper, but it never did (and instead just did a normal no-index diff).

So it seems like the new behavior is actually the right thing, as it makes the --no-index case consistent with the regular one?
I'm not at all clear why you would run "difftool" here if you it is not configured and you just want the straight diff output.