How to ignore whitespace in github when comparing?
GithubGithub Problem Overview
I have committed a file after prettifying it in sublime. Now when I am comparing the differences in GitHub web UI it's showing a lot of changes, so it is very difficult to see the actual changes. Can I compare files in there and ignore the whitespace?
Github Solutions
Solution 1 - Github
On github, you simply append the w=1
parameter to the URL for it to ignore whitespace.
That would look something like:
https://github.com/account_name/repo/pull/14/files?w=1
Solution 2 - Github
Since May 2018, this option is now more visible:
> A diff view with reduced white space has been available since 2011 by adding ?w=1
to the URL.
The new button builds on this view to better support your existing workflows.
Select the new option "Hide whitespace changes
" in that "Diff settings
" new button, and you will see only the relevant changes you want.
Note: since 2018, that setting has been relocated to the setting "gear" symbol:
Since Oct. 2021, this option is now persistent!
> ## Hiding whitespace is now remembered for each pull request > > The diff setting to hide whitespace changes in the pull request Files Changed tab is now remembered for you for that pull request. > > You no longer need to re-enable it when you switch to another tab or when you come back to the same pull request later. > > > > Learn more about reviewing proposed changes in a pull request.
Solution 3 - Github
git diff -w
(alternately git diff --ignore-all-space
) ignores whitespace. You can also add --ignore-blank-lines
if there are a lot of those.
For more details and many more options, check out the docs.
Solution 4 - Github
There is a Chrome plugin GitHub Whitespace by jackchuka that appends ?w=1
to the PR URLs so whitespace is always turned off
Solution 5 - Github
Building on @Anthony and @Alan P's answer, here is a small bookmarklet for those that can't install chrome extensions:
javascript:document.location+="?w=1"