guide/whitespace-options.md

Whitespace Ignore Options Explained — diff -b, -w, -B, -Z and Their git Equivalents

The exact differences between ignoring trailing whitespace, ignoring the amount of whitespace (-b), ignoring all whitespace (-w), ignoring blank lines (-B), and ignoring case, compared with GNU diff and git options and examples.

Last updated: 2026-09-23

When two files "have the same content" yet diff reports lots of changes, whitespace is often the cause: an editor stripped trailing spaces, converted tabs to spaces, or changed the indentation width. diff tools offer options to ignore such differences, but each option ignores a different range of things, so you need to know exactly what each one does.

Whitespace options in GNU diff

OptionLong nameWhat it ignores
-Z--ignore-trailing-spaceWhitespace at the end of a line
-E--ignore-tab-expansionDifferences due to tabs expanded into spaces
-b--ignore-space-changeChanges in the amount of whitespace, trailing whitespace
-w--ignore-all-spaceAll whitespace
-B--ignore-blank-linesChanges that only add or delete blank lines
-i--ignore-caseLetter case
--strip-trailing-crCR characters at the end of input lines

The corresponding git diff options

The git documentation describes them as follows.

The key difference between -b and -w

These two are often confused. The crux is whether they distinguish between whitespace being there and not being there.

LeftRight-b (ignore amount of whitespace)-w (ignore all whitespace)
a ba bSameSame
a babDifferentSame
x = 1x=1DifferentSame
if (a) + trailing spacesif (a)SameSame
Indented with 1 tabIndented with 4 spacesSameSame

-b collapses each run of whitespace to a single space, while -w removes all whitespace. That is why -w treats x = 1 and x=1, and even int a and inta, as the same.

The danger when indentation carries meaning

In files where indentation is part of the syntax, such as Python, YAML, and Makefiles, whitespace options can hide real changes.

if ready:
    start()
    notify()
if ready:
    start()
notify()

In the second version, notify() has moved out of the if statement and the behavior has changed, but comparing with -w removes all whitespace, so the difference disappears. -b does catch it, because the leading whitespace went from "present" to "absent". However, if the indentation changes from 4 to 8 spaces and the code moves one block deeper, only the amount of whitespace has changed, so -b will not show it either.

The safe approach is to compare files where indentation matters with whitespace options turned off. Use whitespace options to confirm that a change is "only cleanup", and make the final check without them.

The scope of ignoring blank lines (-B)

-B and git's --ignore-blank-lines hide changes consisting only of blank lines. If an added blank line sits in the same hunk as another real change, that blank line may still be shown. This is useful for documents where the number of blank lines between paragraphs changed, or when a code formatter adjusted the blank lines between functions.

How this site's options map

This siteClosest GNU diffClosest git diff
Whitespace: Compare as is(no option)(no option)
Whitespace: Ignore trailing whitespace-Z--ignore-space-at-eol
Whitespace: Ignore amount of whitespace-b-b
Whitespace: Ignore all whitespace-w-w
Ignore case-i(none)
Ignore blank linesSimilar to -B (blank lines are excluded from comparison)Similar to --ignore-blank-lines
Normalize line endings--strip-trailing-cr + ignore the final newlineSimilar to --ignore-cr-at-eol

This site's "Ignore blank lines" excludes blank lines from the comparison entirely and only shows them in a faded color. The ignore options also apply to in-line highlighting: with "Ignore amount of whitespace" on, parts that differ only in the number of spaces are not highlighted.

Try it in this tool

Put the examples from the table above into the Text Diff Checker and switch the whitespace options one at a time to see the difference immediately. "Invisible differences" such as a CR at the end of a line or a missing final newline are covered in Line endings and invisible differences, and how to read the result as a patch in How to read a unified diff.

Go to the text diff tool