git diff filtered by file name

Zantier picture Zantier · Mar 15, 2013 · Viewed 13.3k times · Source

I would like the results of git diff to be filtered by the file name.

In particular, I want a diff for all of the files named "AssemblyInfo.cs", but located anywhere within the git repository.

I am using git on Cygwin, if that makes a difference.

Answer

GoZoner picture GoZoner · Mar 15, 2013

File arguments to git diff need to be delimited by -- - try this:

find . -name <pattern> | xargs git diff --

xargs makes sure spaces, tabs, newlines, etc are handled correctly.

You could debug it with the --name-status argument to git diff. You could also try:

git diff --name-only | grep <pattern>

[edit] Try:

git diff --name-status -- `find . -name '<pattern>'`
ebg@taiyo(98)$ git diff --name-status -- `find . -name '*.scm'`
M       scheme/base/boolean.scm
M       surf/compiler/common.scm
M       surf/compiler/compile.scm
M       surf/compiler/expand.scm