Suppress Diffs for Generated Files with -diff

Use the -diff attribute in .gitattributes to hide noisy diffs from generated files, lock files, and minified assets in pull requests.

Diff Settings

Detailed Explanation

Suppressing Diffs with -diff

Some files are tracked by Git but produce diffs that are noisy, unreadable, or meaningless to reviewers. The -diff attribute tells Git to skip textual diff output for these files.

Common Use Cases

# Lock files (auto-generated, massive diffs)
package-lock.json text -diff
yarn.lock         text -diff
pnpm-lock.yaml    text -diff
Cargo.lock        text -diff
poetry.lock       text -diff
composer.lock     text -diff
Gemfile.lock      text -diff
Pipfile.lock      text -diff

# Minified files
*.min.js  text -diff
*.min.css text -diff

# Source maps
*.map     text -diff

# Auto-generated code
*.generated.ts text -diff
*.pb.go        text -diff

What -diff Does

When you run git diff on a file marked with -diff, Git outputs:

Binary files a/package-lock.json and b/package-lock.json differ

The file is still treated as text for line ending normalization (text attribute) and merging, but the diff output is suppressed. This is different from binary, which disables text handling, diff, and merge.

Impact on Pull Requests

On GitHub, GitLab, and Bitbucket, files with -diff are collapsed by default in pull request views. This dramatically improves PR readability by hiding thousands of lines of lock file changes.

text -diff vs binary

Scenario Use
Lock file (text, needs merging, noisy diff) text -diff
Image (binary data) binary
Minified JS (text, no useful diff) text -diff
Compiled .exe (binary data) binary

The key distinction: text -diff still normalizes line endings and allows three-way merge. binary disables all three features.

Selective Diff for Large Files

If a file is large but you still want to see diffs occasionally, you can use git diff --text to override the -diff attribute on the command line.

Use Case

Repositories with JavaScript/Node.js projects (package-lock.json, yarn.lock), Rust projects (Cargo.lock), Python projects (poetry.lock), or any project with auto-generated code should suppress diffs for those files to keep pull requests clean and reviewable.

Try It — .gitattributes Generator

Open full tool