I'm using a git pre-commit hook to check commits. The pre-commit script basically does one thing:
exec git diff-index --check --cached HEAD --
It does some other things too, but they are irrelevant for this discussion.
The problem is, I have all sorts of files in the repository, and not all of them have to comply with the checks that enforced by "git diff-index --check
".
So my question is: how can I exclude/ignore these files? That is, I do track them in git, but I want to ignore them in pre-commit check only.
For instance, a certain patch contains *.c, *.h, *ini, and *.xyz files.
I want the "git diff-index --check
" to apply to .c and .h files only.
The man page says:
When <path> arguments are present, compares only paths matching those patterns. Otherwise all tracked files are compared.
In other words, the "path" arguments are really glob-style patterns, not just specific paths. You can just add '*.c' '*.h'
to your command.
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