Navigation Menu

Skip to content

Is it possible to filter the files in diff for their extensions? #25991

Answered by airtower-luna
manoj798 asked this question in Actions
Discussion options

You must be logged in to vote

You can pass a list of files for git diff to compare against the current HEAD like this:

git diff -- FILE1 FILE2 ...

The file list can be created by a shell glob, that’s what

git diff -- *.json

does. However, *.json matches only files in the current directory. If your files are in subdirectories you have two options:

  1. Use find to build the file list, e.g.
git diff -- $(find . -name *.json)
  1. If you’re using bash you can set the globstar shell option and use ** to match any number of directories:
shopt -s globstar
git diff -- **/*.json

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants