Git – Want to exclude file from “git diff”

diff()gitgit-diff

I am trying to exclude a file (db/irrelevant.php) from a Git diff. I have tried putting a file in the db subdirectory called .gitattributes with the line irrelevant.php -diff
and I have also tried creating a file called .git/info/attributes containing db/irrelevant.php.

In all cases, the db/irrelevant.php file is included in the diff as a Git binary patch. What I want is for the changes to that file to be ignore by the diff command. What am I doing wrong?

Best Answer

Omg, drivers and awk to exclude a lousy file ? Since git 1.9 something you can:

git diff -- . ':(exclude)db/irrelevant.php' ':(exclude)db/irrelevant2.php'

Ah, elegance! See the quoted answer and for details this answer by @torek