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.
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.
To check the staged changes, run the git diff command along with --staged option.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With