如何使用 git-diff 显示空格和制表符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25550582/
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
How to show space and tabs with git-diff
提问by Nico
I have the following output with git-diff.
我有以下带有 git-diff 的输出。
- // sort list based on value
+ // sort list based on value
How can I see easily see the number of removed tabs/spaces at the end of the line ?
如何轻松查看行尾已删除的制表符/空格数?
采纳答案by VonC
Note: Git 2.5+ (Q2 2015) will propose a more specific option for whitespace detection.
注意:Git 2.5+(2015 年第二季度)将为空白检测提出一个更具体的选项。
See commits 0e383e1, 0ad782f, and d55ef3e[26 May 2015] by Junio C Hamano (gitster
).
(Merged by Junioin commit 709cd91, 11 Jun 2015)
请参阅Junio C Hamano ( ) 的提交 0e383e1、0ad782f和d55ef3e[2015 年 5 月 26 日] 。(由Junio在commit 709cd91 中合并,2015 年 6 月 11 日)gitster
diff.c
:--ws-error-highlight=<kind>
optionTraditionally, we only cared about whitespace breakages introduced in new lines.
Some people want to paint whitespace breakages on old lines, too. When they see a whitespace breakage on a new line, they can spot the same kind of whitespace breakage on the corresponding old line and want to say "Ah, those breakages are there but they were inherited from the original, so let's not touch them for now."Introduce
--ws-error-highlight=<kind>
option, that lets them pass a comma separated list ofold
,new
, andcontext
to specify what lines to highlight whitespace errors on.
diff.c
:--ws-error-highlight=<kind>
选项传统上,我们只关心在新行中引入的空格中断。
有些人也想在旧行上绘制空白破损处。当他们在新行上看到空格中断时,他们可以在相应的旧行上发现相同类型的空格中断,并想说:“啊,这些中断在那里,但它们是从原始行继承的,所以我们不要碰它们现在。”介绍
--ws-error-highlight=<kind>
选项,让他们通过一个逗号分隔的列表old
,new
以及context
对指定哪些线来突出空白错误。
The documentation now includes:
该文档现在包括:
--ws-error-highlight=<kind>
Highlight whitespace errors on lines specified by
<kind>
in the color specified bycolor.diff.whitespace
.<kind>
is a comma separated list ofold
,new
,context
.
When this option is not given, only whitespace errors innew
lines are highlighted.E.g.
--ws-error-highlight=new,old
highlights whitespace errors on both deleted and added lines.all
can be used as a short-hand forold,new,context
.
以 指定
<kind>
的颜色突出显示 指定的行上的空白错误color.diff.whitespace
。<kind>
是逗号分隔的old
,new
,列表context
。
如果未给出此选项,则仅new
突出显示行中的空白错误。例如
--ws-error-highlight=new,old
,在已删除和添加的行上突出显示空白错误。all
可以用作 的简写old,new,context
。
For instance, the old commit had one whitespace error (bbb
), but you can focus on the new errors only:
例如,旧提交有一个空格错误 ( bbb
),但您可以只关注新错误:
(test done after t/t4015-diff-whitespace.sh
)
(测试完成后t/t4015-diff-whitespace.sh
)
Update Git 2.11+ (Q4 2016, a year and half later) :
更新 Git 2.11+(2016 年第四季度,一年半之后):
git config diff.wsErrorHighlight [old,new,context]
git diff/log --ws-error-highlight=<kind>
lacked the corresponding configuration variable to set it by default. That is added in Git 2.11.
git diff/log --ws-error-highlight=<kind>
缺少相应的配置变量来默认设置它。这是在 Git 2.11 中添加的。
See commit 0b4b42e, commit 077965f, commit f3f5c7f(04 Oct 2016) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
--in commit e5272d3, 26 Oct 2016)
请参阅Junio C Hamano() 的commit 0b4b42e、commit 077965f、commit f3f5c7f(2016 年 10 月 4 日)。(由Junio C Hamano合并-- --在提交 e5272d3 中,2016 年 10 月 26 日)gitster
gitster
回答by knittl
I can think of multiple options:
我可以想到多种选择:
Configure Git to use colors:
git config --global color.ui true
. Whitespace at the end of lines is now highlighted in red.Pipe the output of
git diff
throughcat
:git diff | cat -A
. The-A
flag tellscat
to show non-printable characters (e.g.^I
for tab).
配置 Git 以使用颜色:
git config --global color.ui true
. 行尾的空白现在以红色突出显示。管道输出
git diff
throughcat
:git diff | cat -A
。该-A
标志告诉cat
显示不可打印的字符(例如^I
制表符)。