Michael Michael - 1 year ago 43
Git Question

Want to exclude file from "git diff"

I am trying to exclude a file (

) from a Git diff. I have tried putting a file in the
subdirectory called
with the line
irrelevant.php -diff

and I have also tried creating a file called

In all cases, the
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?

Answer Source

You could set up a custom diff driver with a no op command and assign it to those files that should be ignored.

Create a repository specific diff driver with this command

git config diff.nodiff.command /bin/true

or for all your repos with --global.

(If /bin/true doesn't exist in MacOS, alternatives would be using /usr/bin/true or echo).

Then, assign the new diff driver to those files you want ignored in your .git/info/attributes file.

irrelevant.php    diff=nodiff

If this state is supposed to be shared with other developers you could use .gitattributes instead of .git/info/attributes and share the git config command with your peers (through a documentation file or something).