26

Is there a way to display a commit on github.com without showing whitespace changes?

Is there a way to display that from console? i.e. clone and then look at commit (tree) locally ignoring all white space changes?

I use Trac extensively; I'm looking for something similar to Ignore White space changes (which can be found on the changeset view).

wovano
  • 4,543
  • 5
  • 22
  • 49
Martin Tóth
  • 1,747
  • 3
  • 24
  • 35
  • https://gist.github.com/xPaw/de6ee132a2e267ef6960: Adds a button in GitHub UI to ignore whitespace changes in commits – Martin Tóth Jun 20 '15 at 15:45

4 Answers4

67

Append ?w=1 to the URL on any github.com page that is showing a diff and it will ignore whitespace. See this blog post.

balexand
  • 9,549
  • 7
  • 41
  • 36
20

There is a trio of options that you can use at the command line (with any of git's diff commands) for this:

  • --ignore-space-at-eol Ignore changes in whitespace at EOL.
  • -b, --ignore-space-change Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.
  • -w, --ignore-all-space Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.

I don't believe github has implemented anything using these options.

laalto
  • 150,114
  • 66
  • 286
  • 303
Cascabel
  • 479,068
  • 72
  • 370
  • 318
1

Sadly the X thing is gone and alongside the previous snippet is rendered useless. Here is something that should work for now:

var i, e, tr, tdL, tdR, textL, textR, text = function (el) { return el.parentNode.children[2].children[1].children[0].textContent.replace(/\s/g, '').substr(1); }
for (i = 0, e = document.getElementsByClassName('gd'); i < e.length; ++i) {
    tr = e[i].parentNode.parentNode.parentNode;
    if ('&nbsp;' !== tr.children[1].innerHTML) { continue; }
    tdL = tr.children[0];
    tdR = document.getElementById(tdL.id.replace(/^L(\d+)L/, 'L$1R')),
    textL = text(tdL);
    textR = text(tdR);
    if (textL === textR) { tdL.parentNode.style.display = tdR.parentNode.style.display = 'none'; }
}
helmer
  • 19
  • 3
0

After looking into source HTML of commit page, I've found out that github marks pure whitespace changes with "x" CSS class... Which makes the following oneliner possible:

jQuery.expr[':'].hasX = function(obj) { var $this = $(obj); return ($this.find('.x').length && $this.next().find('.x').length); }; jQuery('.data tbody tr:hasX').toggle().next().toggle();

What it does, is runs through all rows of the commit table, and hides rows if given line and the one after that do have ".x" element in them.

Here's full JS:

// create new selector
jQuery.expr[':'].hasX = function(obj) {
    // cache
    var $this = $(obj);
    // whether this and next line do have '.x' element as child
    return $this.find('.x').length && $this.next().find('.x').length;
}

// select all rows and hide (ones containing "-")
jQuery('.data tbody tr:hasX').toggle()
// hide the ones after selected (ones containing "+")
    .next().toggle();
Martin Tóth
  • 1,747
  • 3
  • 24
  • 35