How to exclude files in "git diff-index"

I am using git pre-commit hook to check commits. The pre-commit script basically does one thing:

exec git diff-index --check --cached HEAD -- 

He also does some other things, but they are not relevant to this discussion.

The problem is that I have all kinds of files in the repository, and not all of them have to perform checks that are performed using " git diff-index --check ".

So my question is: how can I exclude / ignore these files? That is, I track them in git, but I want to ignore them only when checking before committing.

For example, a specific patch contains * .c, * .h, * ini and * .xyz files. I want git diff-index --check apply only to .c and .h files.

+3
git
source share
1 answer

The manual page says:

When the <path> arguments, only paths matching these patterns are compared. Otherwise, all monitored files are compared.

In other words, the path arguments are truly globe-style patterns, not just specific paths. You can simply add '*.c' '*.h' to your team.

+6
source share

All Articles