Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In git diff, how to exclude root level files

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 /.

like image 976
ChikChak Avatar asked Jul 22 '26 21:07

ChikChak


2 Answers

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.

like image 144
Guildenstern Avatar answered Jul 25 '26 13:07

Guildenstern


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.

like image 42
j6t Avatar answered Jul 25 '26 12:07

j6t



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!