Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files in "git diff-index"

Tags:

git

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.

like image 977
kliteyn Avatar asked Oct 08 '13 15:10

kliteyn


1 Answers

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.

like image 150
torek Avatar answered Sep 20 '22 20:09

torek