问题
Per @VonC's answer in https://stackoverflow.com/a/56212234 in Git 2.22.0 (released 2019-06-08), a number of changes were made to the git difftool
command regarding how its configuration is determined.
However, unless I am missing something here, it appears that a regression in functionality has been introduced in this version. In previous versions, including 2.21.0, it has been possible to use git difftool
without any configuration or CLI options, in which case it passes through to git diff
.
Now in Git 2.22.0 if I use git difftool
without configuring diff.tool
or merge.tool
, I get the following message:
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
Is there any way of bypassing this error and returning to the old behavior of passing through to git diff
or must I call git diff
directly?
edit: According to Jeff King's mailing list reply, the new behavior is intentional. However at the top of the git-difftool documentation, it says that:
git difftool is a frontend to git diff and accepts the same options and arguments. See git-diff[1].
Is this no longer the case?
回答1:
TLDR; The new error message "This message is displayed because 'diff.tool' is not configured.
" might be an actual bug fix, and not a new error.
I just tried and... didn't get any error message (when used without parameters).
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
Plus, this error message has been introduced in commit 5338a6a, Jan. 2013, Git v1.8.2-rc0.
I did mentioned commit 05fb872 from Git 2.22, which uses ${GIT_MERGETOOL_GUI}
.
That environment variable is not set on my machine, and I don't get any error message.
Check your own git config
and environment variables.
I do see the error message in Git 2.22 with:
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
With Git 2.21.0, it does default to a regular 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
From the OP Git mailing list thread:
Denton Liu pinpoints the original commit 287ab28 (16 Feb 2019) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 12e5bdd, 07 Mar 2019)
diff
: reuse diff setup for--no-index
caseWhen "
--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 setsGIT_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 guessdifftool
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 rungit-diff
, expecting it to trigger the helper, but it never did (and instead just did a normalno-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 straightdiff
output.
来源:https://stackoverflow.com/questions/56675863/git-2-22-0-difftool-no-longer-passes-through-to-git-diff-if-diff-tool-is-unset