I have this configuration on my repo:
echo '*.java diff=java' >> .gitattributes
and when I do git diff ... I get the expected results.
However, I'm doing a script to analyse other git repositories, so I usually do:
git --git-dir='/path/to/repo/.git' diff ...
What I would like to do is to run the script like that, and have the same results as if the attribute was present. I don't want to set global attributes or add a .gitattributes to the git project I want to analyse. I wouldn't mind something like
git --git-dir='/path/to/repo/.git' diff --word-diff-regex=<java-rexeg>
But I don't know how to get the java regex git uses.
From git help config:
core.attributesfileIn addition to
.gitattributes(per-directory) and .git/info/attributes, git looks into this file for attributes (seegitattributes(5)). Path expansions are made the same way as forcore.excludesfile. Its default value is $XDG_CONFIG_HOME/git/attributes. If$XDG_CONFIG_HOMEis either not set or empty,$HOME/.config/git/attributesis used instead.
In other words, you can create your own attributes file at $XDG_CONFIG_HOME/git/attributes, and pass XDG_CONFIG_HOME to your git invocation like this:
XDG_CONFIG_HOME=config_dir git --git-dir='/path/to/repo/.git' diff ...
Because you control exactly what is XDG_CONFIG_HOME, it would not be truly global - you can do it totally on a fly.
Or, it may be simpler to create global git attributes file in $HOME/.config/git/attributes instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With