git 在 github 上提交没有空格更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4449834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Commit without whitespace changes on github
提问by Martin Tóth
Is there a way to display a commit on github.com without showing whitespace changes?
有没有办法在 github.com 上显示提交而不显示空格更改?
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).
我广泛使用 Trac;我正在寻找类似于Ignore White space changes
(可以在变更集视图中找到)的东西。
回答by balexand
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.
附加?w=1
到显示差异的任何 github.com 页面上的 URL,它将忽略空格。请参阅此博客文章。
回答by Cascabel
There is a trio of options that you can use at the command line (with any of git's diff commands) for this:
为此,您可以在命令行(使用任何 git diff 命令)使用三个选项:
--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.
--ignore-space-at-eol
在 EOL 时忽略空格的变化。-b, --ignore-space-change
忽略空格量的变化。这会忽略行尾的空格,并认为一个或多个空格字符的所有其他序列是等效的。-w, --ignore-all-space
比较行时忽略空格。即使一行有空格而另一行没有空格,这也会忽略差异。
I don't believe github has implemented anything using these options.
我不相信 github 已经使用这些选项实现了任何东西。
回答by helmer
Sadly the X thing is gone and alongside the previous snippet is rendered useless. Here is something that should work for now:
可悲的是,X 的东西不见了,与之前的代码片段一起变得毫无用处。这是现在应该起作用的东西:
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 (' ' !== tr.children[1].innerHTML) { continue; }
tdL = tr.children[0];
tdR = document.getElementById(tdL.id.replace(/^L(\d+)L/, 'LR')),
textL = text(tdL);
textR = text(tdR);
if (textL === textR) { tdL.parentNode.style.display = tdR.parentNode.style.display = 'none'; }
}
回答by Martin Tóth
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:
在查看提交页面的源 HTML 后,我发现 github 用“x”CSS 类标记了纯空白更改......这使得以下 oneliner 成为可能:
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.
它的作用是遍历提交表的所有行,如果给定的行和后面的行中确实有“.x”元素,则隐藏行。
Here's full JS:
这是完整的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();