0

简短的问题是:如何制作

git diff

调用

git difftool -t opendiff -y

? 第二行是调用opendiffdiff 一些文件,即使事先没有进行任何配置(我git在 macOS Catalina 和 Big Sur 上使用的是 1.9.2 版本和当前的 Xcode 12.1)。

线

git config --global diff.external 'git difftool -t opendiff -y'

不起作用。


更长的细节:

我们可以很容易地调用opendiffusing git difftool -t opendiff -y,因此git知道如何在opendiff没有任何额外配置的情况下将其用作可视差异工具。并且在 github 上有一种方法可以diff.external用来调用单独的 shell 脚本来调用opendiff.

因此,既然git很容易知道如何调用opendiffusing 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 difftoolwith opendiff?看起来git diff而且git difftool有点特别,因为我们甚至配置了默认difftool使用 usinggit config --global diff.tool opendiff所以我们触摸diff到 configure difftool。因此,从某种意义上说git diffgit 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 脚本的情况下使用。

4

0 回答 0