Want to exclude file from "git diff"

Solution 1:

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 Winodws, replace the single quotes ' by double quotes ".)

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

Solution 2:

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).