Tech Note
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Exclude Files In Git Diffs

A useful incantation of git diff which can be used to exclude files in the diff output.

git diff -- ':!file/to/exclude.php' ':!file/to/exclude.php'

Or simply:

git diff -- ':!file/to/exclude.php' ':!file/to/exclude.php'

This can be extended to glob patterns as well. For example, an incantation that can be used to ignore all generated mock files and gRPC files in a Go project:

git diff -- ':!*.pb.go' ':!mock'

Source: Stack Overflow