Recently whilst running a git diff, I noticed my difftool was getting stuck. I discovered there was a file containing a large binary causing the issue. I didn't need to see the changes in this file, so I started looking for ways to ignore it.
It turns out there is a handy syntax called a pathspec which can be used to filter out files and directories.
This is passed directly into the diff command.
$ git difftool origin/master ':(exclude)test_data/data.json'
With this in place, the
data.json file will be excluded from the diff, allowing my difftool to easily handle the rest of the files.
Pathspecs can also be used with other git commands. To see other ways to use them, take a look at the pathspec section of the git glossary.