Search code examples
gitgit-diffgit-pathspec

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


Solution

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