In git diff, how to exclude root level files

128 views Asked by At

I want to get files changed between branches, but I want to filter out root level files, meaning files that aren't in any directory.

These files can be identified by that they don't have / in their path.

I know for example that if I want to exclude some dir I can do

git diff .... -- :!dir_name

However, I'm not sure how to add an exclusion to files without /.

3

There are 3 answers

0
Guildenstern On BEST ANSWER

This works for me on Bash on Linux:

git diff ':/*/**'

These * are supposed to be interpreted by Git, not by the shell. That’s why I’m using single quotes.

3
j6t On

If you do not insist in how to exclude files, you can use

git diff HEAD~7 -- '*/*'

i.e., you include everything that has at least one / in the name.

0
ElpieKay On

Try the pathspec,

git diff -- ':(glob,exclude)*'

If the current directory is not the root of the repository, add the signature top,

git diff -- ':(glob,top,exclude)*'

:(glob,top)* matches the files in the root of the repository. With the signature exclude, it matches the files in the subdirectories.