brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git diff -w hides changes that are only whitespace

Git
~/tips/tip-git-diff-ignore-whitespace

git diff -w

Leaves out indentation and spacing changes so you can read the real edits.

When someone re-indents a file and fixes a bug in the same commit, the bug fix disappears in a sea of red and green. -w filters the noise out.

git diff -w

-w is short for --ignore-all-space: git ignores whitespace when it compares lines. A line that only changed its indentation or got an extra space no longer shows up, and a file with only that kind of change disappears from the diff completely.

There are milder versions. -b (--ignore-space-change) ignores changes in the amount of whitespace but not whitespace added where there was none. --ignore-blank-lines drops added or removed empty lines. They work with git show and git log -p too, which is how I’d read a big reformatting commit:

git show -w a1b2c3d

Whitespace sometimes matters. In Python, YAML and Makefiles, indentation is part of the meaning, so -w can hide a change that breaks everything. I’d use it to read, never to decide whether a diff is harmless. Also, a patch you save from git diff -w leaves the whitespace changes out, so it won’t apply cleanly to the original files.

Further reading: git-diff documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link