Exclude a directory from git diff

Based on this answer you can also use:

git diff previous_release..current_release -- . ':!spec'

This is a newish git feature which allows excluding certain paths. It should be more reliable than various shell oneliners.

I'm posting this here because this question is still the #1 hit for "git diff exclude path".

Since Git 2.13 (Q2 2017), you can replace ! with ^. The latter doesn't need quotes. So you can write it as:

git diff previous_release..current_release -- . :^spec

Assuming you use bash, and you've enabled extended globbing (shopt -s extglob), you could handle that from the shell side:

git diff previous_release current_release !(spec)

Saves you having to list all other things.

Or, shell-agnostic:

git diff previous_release current_release --name-only | grep -v '^spec/' \
    | xargs git diff previous_release current_release --

You could wrap that up in a one-liner shell script to save yourself having to retype the arguments.