The short question is: how to make
git diff
invoke
git difftool -t opendiff -y
? The second line is to invoke opendiff
to diff some files, even when there is no configuration whatsoever done beforehand (I am using git
version 1.9.2 and the current Xcode 12.1 on macOS Catalina and Big Sur).
The line
git config --global diff.external 'git difftool -t opendiff -y'
does not work.
Longer details:
We can readily invoke opendiff
using git difftool -t opendiff -y
, so git
knows how to use opendiff
as a visual diff tool without any additional configuration. And there is a way on github about how to use diff.external
to invoke a separate shell script to invoke opendiff
.
So since git
readily knows how to invoke opendiff
using difftool
, we really should not need to use an external shell script. For the fact that diff.external
can invoke any external command, then it would appear logical to even invoke itself, which is to invoke git difftool -t opendiff -y
, but the line
git config --global diff.external 'git difftool -t opendiff -y'
won't work and can cause an error when we do a git diff
afterwards. (it may appear it is due to git
passing additional arguments to the "external" command?) The error it gives is:
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.
How to make it work so that git diff
can invoke the git difftool
with opendiff
? It seems git diff
and git difftool
is a little bit adhoc, because we even configure the default difftool
to use using git config --global diff.tool opendiff
so we are touching diff
to configure difftool
. So in a way git diff
and git difftool
look like separate things but in a way they look like they are one unit.
One way to make it work but using an alias is
git config --global alias.diffy 'difftool -t opendiff -y'
but then we will need to use git diffy
to run it instead of git diff
. We can also create a Bash or Zsh alias gitdiff
to run git difftool -t opendiff -y
but it seems we should be able to use git diff
without setting up an additional shell script.