Quick Tip: How to Hide Whitespace Changes in Git Diffs

Programming - Apr 19, 2024

Screenshot of a code diff before and after hiding whitespace.

If you’ve ever had to review a pull request where the only code change is adding or removing a wrapper element, you’ll be familiar with the pain of reviewing what appears to be a massive change but is actually trivial.

In this example I’ve added a wrapper element and removed some inner elements. By default, it looks like I changed almost every line. That’s because git is highlighting every line that had an indentation change. When I hide whitespace changes, it becomes quite clear what I added and removed.

Most Git hosting services support the ability to hide whitespace changes by adding ?w=1 as a URL parameter. Let’s explore how to hide whitespace changes for some of the big players.

You can hide whitespace changes for GitHub diffs in two ways. First, click the gear icon near the top of the page and check the “Hide whitespace changes” option.

Screenshot of the GitHub UI, showing the "hide whitespace changes" option.

Or, you can add ?w=1 to the URL.

You can hide whitespace changes for GitLab diffs in two ways. First, click the “Hide whitespace changes” button near the top of the page.

Screenshot of the GitLab UI, showing the "hide whitespace changes" button.

Or, you can add ?w=1 to the URL.

You can hide whitespace changes for Bitbucket diffs by adding ?w=1 to the URL.

Previous Next
Copyrights
We respect the property rights of others, and are always careful not to infringe on their rights, so authors and publishing houses have the right to demand that an article or book download link be removed from the site. If you find an article or book of yours and do not agree to the posting of a download link, or you have a suggestion or complaint, write to us through the Contact Us .
Read More