How to ignore whitespace in a diff

Reformatting a file can make every line look changed. Here's how to hide whitespace-only changes in Git, on the command line and in Diffspot, and when you shouldn't.

Updated November 14, 2026

Kinds of whitespace changes

In Git

OptionIgnores
git diff --ignore-space-at-eolWhitespace changes at line ends
git diff -b (--ignore-space-change)Changes in the amount of whitespace
git diff -w (--ignore-all-space)All whitespace when comparing lines
git diff --ignore-blank-linesAdded or removed blank lines
git diff --ignore-cr-at-eolCarriage returns at line ends (CRLF vs LF)

The same flags work with git show and git log -p. On GitHub, add ?w=1 to a pull request's "Files changed" URL to hide whitespace changes.

With the diff command

GNU diff has matching options: -Z (trailing), -b (amount), -w (all), -B (blank lines) and --strip-trailing-cr. For example, diff -u -w old.py new.py.

In Diffspot

Open the Ignore menu and choose one of Ignore trailing whitespace, Ignore changes in whitespace or Ignore all whitespace, and optionally Ignore blank lines. Line endings never count as changes. The text boxes keep the original text, so merging and exporting still use your exact content.

Ignore rules also go beyond whitespace: you can ignore letter case, mask out timestamps, dates, UUIDs, hex hashes, IP addresses and numbers, or ignore whole lines that match a regular expression, such as comment lines.

When not to ignore whitespace

In Python, YAML, Makefiles and Haskell, indentation is part of the meaning. A line moving in or out of a block is a real change that -w would hide. Review those files with whitespace visible, or at least check the indentation of the lines that remain changed.

Compare code, ignoring whitespace

More guides