Exclude paths from the Git diff command

This is usefull if you for example have one or more subtrees in your project and you do not want to see changes made in those in your diff

Say you have a folder called ‘common’. This is how to exclude it from git diff:

git diff origin/master -- . ':!/common'

Now if you have a specific file that you want to exclude the command looks like this:

git diff origin/master -- . ':!/rules/form.xml'

And if you want to exclude multiple files of folders:

git diff origin/master -- . ':!/rules/form.xml' ':!/common'

NOTE! ‘origin/master’ is just an example and not part of the solution.

Tested on Git vesion 2.23.0 on Windows 10

Comments are closed.

Niklas Tech Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.