Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore whitespace in github when comparing?

Tags:

github

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?

like image 995
shekhardtu Avatar asked May 03 '16 14:05

shekhardtu


People also ask

How do I ignore a space in git?

We use the git diff --ignore-space-at-eol command to ignore whitespace changes at the end of our lines. Whitespaces at the beginning and in the middle of lines will remain in the git diff output. The git diff --b is the short form for the git diff --ignore-space-change that ignores whitespace at the line end.

How do I ignore whitespace in diff?

The --ignore-trailing-space ( -Z ) option ignores white space at line end. Re: "-w or --ignore-all-space option does not ignore newline-related changes" So -w ignores all whitespace, except for the whitespace it doesn't ignore.

How do I ignore whitespace in Vscode?

It's also available in Preferences,Settings. File => Preferences => Settings => Diff Editor => Ignore Trim Whitespace.


2 Answers

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 
like image 195
Anthony Avatar answered Sep 29 '22 21:09

Anthony


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.

https://user-images.githubusercontent.com/602352/39442176-66700966-4c7e-11e8-91a9-a71db12eeac7.png

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:

https://help.github.com/assets/images/help/pull_requests/diff-settings-menu.png


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.

https://i1.wp.com/user-images.githubusercontent.com/2503052/137387087-91cc8458-9e11-44a9-8da0-f48251ec452c.gif?ssl=1 -- hide-whitespace2

Learn more about reviewing proposed changes in a pull request.

like image 36
VonC Avatar answered Sep 29 '22 22:09

VonC