I found a great Git function, which will unzip a file and use the uncompressed result in a diff, using .gitattributes, plus a change to your local repo config or to the global git config. This is how Simulink *.slx files are - they are zip compressed XML files, basically (maybe with some other added stuff).
However, this requires me to add a .gitattributes to every repo that needs this update - and it's config.
The particular changes needed are:
Add the following line to .gitattributes
:
*.slx diff = slx
Add the following lines to the local repo config (one method: git config -e
):
[diff "slx"]
textconv = unzip -c -a
The goal would be that if I set up the global function locally, Git would know to uncompress any *.slx file in any repo.
Edit: As LightCC found, you're supposed to be able to put these in your home .git/config/attributes
or other file you set via core.attributesFile
. Note that any existing .gitattributes
entry can override any settings in core.attributesFile
. The priority of competing entries is that those "closer to" the file override those "further away from" the file. For instance, if the directory's .gitattributes
says *.ext a=b
, this overrides the top work-tree directory .gitattributes
setting of *.ext a=c
, which overrides core.attributesFile
*.ext a=d
.
The short answer is no: you can define the diff textconv filter in your (personal, global-to-you) .gitconfig
using, e.g., git config --global -e
. However, you must have a .gitattributes
per-repository.
It's worth adding that this idea of defining attributes in a .gitattributes
(which has to be per-repository) but defining the drivers for them—whether they're textconv drivers for diff, merge drivers for git merge
, or filter drivers for checkin/checkout—is a little bit broken, in my opinion at least. The problem is that the .gitattributes
file gets copied automatically on git clone
, but the drivers don't.
There's a fundamental security issue that prevents Git from having the drivers copied on clone, so this is reasonable. But it's clearly not a great situation. Note that git-lfs gets around it by updating the per-repository configuration automatically; you can use the same sort of solution by running your own command, instead of git
, that invokes Git while also fussing with your configuration.