Want to exclude file from "git diff" Want to exclude file from "git diff" git git

Want to exclude file from "git diff"


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


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


This method is shorter than the accepted answers.

git diff 987200fbfb 878cee40ba --stat -- ':!*.cs'

For more information about the different inclusion/exclusion possibilities read this other post