liam.pm

Excluding files from a git diff

You can exclude certain files from a git diff using pathspec exclusion:

git diff origin/feature/TKT-123..HEAD ':(exclude)**/packages.lock.json'

Multiple exclusions

git diff origin/feature/TKT-123..HEAD ':(exclude)**/package-lock.json' ':(exclude)**/yarn.lock' ':(exclude)**/*.min.js'

Just see the file names

git diff --name-only origin/feature/TKT-123..HEAD ':(exclude)**/package-lock.json'

Other useful patterns

# Exclude entire directories
git diff HEAD~1..HEAD ':(exclude)node_modules/**'

# Exclude file types
git diff HEAD~1..HEAD ':(exclude)*.log' ':(exclude)*.tmp'

Note: The :(exclude) pathspec works with other git commands too, like git log, git add, and git status.