简短的问题是:如何制作
git diff
调用
git difftool -t opendiff -y
? 第二行是调用opendiff
diff 一些文件,即使事先没有进行任何配置(我git
在 macOS Catalina 和 Big Sur 上使用的是 1.9.2 版本和当前的 Xcode 12.1)。
线
git config --global diff.external 'git difftool -t opendiff -y'
不起作用。
更长的细节:
我们可以很容易地调用opendiff
using git difftool -t opendiff -y
,因此git
知道如何在opendiff
没有任何额外配置的情况下将其用作可视差异工具。并且在 github 上有一种方法可以diff.external
用来调用单独的 shell 脚本来调用opendiff
.
因此,既然git
很容易知道如何调用opendiff
using difftool
,我们真的不需要使用外部 shell 脚本。对于可以调用任何外部命令的事实diff.external
,那么调用自身似乎是合乎逻辑的,即调用git difftool -t opendiff -y
,但是行
git config --global diff.external 'git difftool -t opendiff -y'
将不起作用,并且在我们git diff
之后执行时可能会导致错误。(这可能是由于向git
“外部”命令传递了额外的参数?)它给出的错误是:
fatal: 234c9c6e7d7f2798068d2f6ee434af9a9dd88123: no such path in the working tree.
Use 'git <command> -- <path>...' to specify paths that do not exist locally.
external diff died, stopping at foo.rb.
如何使其工作以便git diff
可以调用git difftool
with opendiff
?看起来git diff
而且git difftool
有点特别,因为我们甚至配置了默认difftool
使用 usinggit config --global diff.tool opendiff
所以我们触摸diff
到 configure difftool
。因此,从某种意义上说git diff
,git difftool
它们看起来像是独立的事物,但从某种意义上说,它们看起来像是一个整体。
使其工作但使用别名的一种方法是
git config --global alias.diffy 'difftool -t opendiff -y'
但随后我们将需要使用git diffy
来运行它而不是git diff
. 我们也可以创建一个 Bash 或 Zsh 别名gitdiff
来运行git difftool -t opendiff -y
,但似乎我们应该能够在git diff
不设置额外的 shell 脚本的情况下使用。