Is it somehow possible to ignore certain files during git diff? I'm specifically interested in filtering out Makefile.in, Makefile, configure (and all that auto-generated crap).
-
You could add them all to your `.gitignore` file; if they are auto-generated, does it make sense to store them in your source control system? – sarnold Aug 13 '10 at 05:57
-
I'm not storing them there, that's the whole problem. If I would I would just take them out, easy-peasy. This is upstream problem. But I need to diff two different upstream branches and all I get is just tons of this auto-generated junk. Pretty much impossible to do any real comparison work. – Šimon Tóth Aug 13 '10 at 05:59
5 Answers
You can try passing a list of files to git diff
, and it will execute the diff only on those files.
Depending on how your code is setup, it can be as easy as:
git diff otherbranchname -- src/ # only give me diffs from src/
or as unsightly/complex as:
git diff otherbranchname -- $( git ls-files |
perl -lne'next if /(?:[mM]akefile(?:\.in)?|configure|whateverelse)/;print' )
# diff all files which don't match the pattern
Depending on whether the files you want to ignore are managed by Git in the current branch or not, you'll need to replace the git ls-files
with a find *
; use instead a find .
and add |.git
to the Perl expression.
Tailor this as you see fit, possibly using the directories / file names you know you'd like to diff, rather than using the git ls-files
or find
.

- 2,924
- 20
- 18
-
-
Untracked files won't show up in the diff, though - I'd think `ls-files` would always be plenty, unless for some reason you *want* a diff for some untracked files. – Cascabel Aug 13 '10 at 11:39
Another similar solution (add to .git/config
):
[alias]
mydiff = !git diff -- $(git diff --name-only | grep -Ev "([mM]akefile|configure)")
Then run it with:
git mydiff
Note that git diff --name-only
is better than git ls-files
because it will pass a shorter list of files to git diff
, since only files that are modified will be included. I've run into trouble with exceeding the maximum number of arguments in large projects when using git ls-files
.

- 580
- 7
- 13
Regarding gitignore and autotools integration, you might be interested in git.mk: http://mail.gnome.org/archives/desktop-devel-list/2009-April/msg00211.html

- 31,633
- 21
- 64
- 68
As detailed here you can use an exclude
pathspec magic
git diff -- . ':(exclude)Makefile*' ':(exclude)configure'

- 1
- 1

- 32,208
- 39
- 178
- 361
If you want to ignore the content of the diffs but still do care whether the files have changed, this is a job for .gitattributes
and the diff
attribute. Say you have a directory structure like
repo
repo/foo
repo/foo/Makefile
repo/bar
repo/bar/Makefile.in
repo/bar/baz
repo/bar/baz/Makefile.in
If you want to ignore all three Makefiles, create repo/.gitattributes
as:
Makefile* -diff
If you want to ignore bar/Makefile.in
but not the others, create repo/bar/.gitattributes
as
Makefile.in -diff
but also repo/bar/baz/.gitattributes
as
Makefile.in diff
For more detail of what can be done with .gitattributes
, see the docs; my examples are drawn from theirs, made specific to diff.
(h/t to user3589608's answer here)

- 153
- 1
- 7