No effect when doing git diff -- ':(exclude)package-lock.json'

Viewed 1898

I want to a do a diff but without package-lock.json which is huge and is a generated file so nothing interesting for me there. I tried both :

git diff -- ':(exclude)package-lock.json'

git diff -- ':!package-lock.json'

but it has just zero output. What am I doing wrong ? I am running git 2.21.0

2 Answers

Before using exclude pathspec you need to list non-exclude paths. Dot, for example, or a magic root :/:

git diff -- . ':(exclude)package-lock.json'
git diff -- . ':!package-lock.json'

If you don't want to have to add arguments every time you run git diff, you can add a .gitattributes file to the root of your repository, and then add the following line to it (well, actually two lines, but the first line is an explanatory comment, and is optional):

#exclude package-lock from git diff
package-lock.json -diff

After you add that file you will be able to do a regular old git diff, with no additional arguments, and still not have to look at all the package-lock.json diff.

Related