Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff filtered by file name

Tags:

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.

like image 980
Zantier Avatar asked Mar 15 '13 17:03

Zantier


People also ask

How do you tell the difference in files in git?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

Which option is used in git diff to only view the files that were modified?

To check the staged changes, run the git diff command along with --staged option.

What is git diff -- name only?

The -z to with git diff --name-only means to output the list of files separated with NUL bytes instead of newlines, just in case your filenames have unusual characters in them. The -0 to xargs says to interpret standard input as a NUL-separated list of parameters.


2 Answers

The simplest method is to simply use a wildcard:

git diff -- '*AssemblyInfo.cs' 


At least this works on my Git v1.8.4, bash 3.2, and zsh 5.7.

like image 160
AggieBlue Avatar answered Sep 24 '22 19:09

AggieBlue


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 
like image 44
GoZoner Avatar answered Sep 23 '22 19:09

GoZoner