gitdiffgit-diff

Exclude file from "git 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?


Solution

  • 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'
    

    (On Windows, replace the single quotes ' by double quotes ".)

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