在应用补丁时,“1行添加空格错误”是什么意思?

时间:2021-03-28 18:36:57

I'm editing some markdown files of a cloned remote repository, and wanted to test creating and applying patches from one branch to another. However, every time I make any change at all, I get the following message during git apply:

我正在编辑一个克隆的远程存储库的一些markdown文件,并希望测试创建和应用从一个分支到另一个分支的补丁。但是,每当我做任何更改时,我在git应用程序中得到以下消息:

0001-b.patch:16: trailing whitespace.
warning: 1 line adds whitespace errors.

(This is happening on my Mac, and I don't know where the original code was created.)

(这发生在我的Mac上,我不知道原始代码是在哪里创建的。)

What does the warning message mean, and do I need to care?

警告信息是什么意思,我需要关心吗?

4 个解决方案

#1


91  

You don't need to care.

你不需要关心。

The warning enacts a standard of cleanliness of text files in regard to whitespace, the kind of thing that many programmers tend to care about. As the manual explains:

该警告在空格处执行了文本文件的整洁标准,这是许多程序员所关心的事情。随着人工解释道:

What are considered whitespace errors is controlled by core.whitespace configuration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.

被认为是空白的错误是由核心控制的。空白的配置。默认情况下,尾随的whitespaces(包括单独由空格组成的行)和一个空格字符,在该行的初始缩进中立即后跟一个制表符,被认为是空格错误。

By default, the command outputs warning messages but applies the patch.

默认情况下,命令输出警告消息,但应用补丁。

So, the "error" means that the change introduces a trailing whitespace, a whitespace-only line, or a space that precedes a tab. Other than that fact, there is nothing erroneous about the change, and it will apply cleanly and correctly. In other words, if you don't care about the "incorrect" whitespace, feel free to ignore the warning or turn it off with git config apply.whitespace nowarn.

因此,“错误”意味着该更改将引入尾随空格、空白行或在选项卡之前的空格。除了这一事实之外,这一变化没有任何错误,它将干净利落地应用。换句话说,如果您不关心“不正确”的空格,可以随意忽略警告或使用git配置关闭它。空格nowarn。

#2


3  

One case when you could legitimately care is when you want to differentiate between "old" whitespase error (that you might want to keep for legacy reason) and "new" whitespace errors (that you want to avoid).

当您想要区分“老”的whitespase错误(您可能希望保留遗留的原因)和“新的”空白错误(您想要避免的)时,您可以合理地关心的一种情况是。

To that effect, 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 Junio in commit 709cd91, 11 Jun 2015)

由Junio C . Hamano (gitster)提交的,提交0e383e1, 0ad782f和d55ef3e[2015年5月26日]。(由Junio于2015年6月11日合并)

diff.c: --ws-error-highlight=<kind> option

Traditionally, 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 of old, new, and context to specify what lines to highlight whitespace errors on.

引入——ws-error-highlight= 选项,允许它们通过一个逗号分隔的旧的、新的和上下文的列表来指定要突出空格错误的行。

The documentation now includes:

现在的文档包括:

--ws-error-highlight=<kind>

Highlight whitespace errors on lines specified by <kind> in the color specified by color.diff.whitespace.
<kind> is a comma separated list of old, new, context.
When this option is not given, only whitespace errors in new 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 for old,new,context.

——ws-error-highlight=new,old强调了删除和添加行中的空格错误。所有这些都可以作为旧的、新的、上下文的缩写。

For instance, the old commit had one whitespace error (bbb), but you can focus on the new errors only (at the end of still bbb and ccc):

例如,旧的commit有一个空格错误(bbb),但是您可以只关注新的错误(在仍然bbb和ccc的末尾):

在应用补丁时,“1行添加空格错误”是什么意思?

(test done after t/t4015-diff-whitespace.sh)

(测试完成后t / t4015-diff-whitespace.sh)

#3


1  

The whitespace error with visual images is shown here.

这里显示了带有可视图像的空格错误。

http://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#Commit-Guidelines

http://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project Commit-Guidelines

#4


-1  

Because line begining with TAB istead of SPACE. Go on patch file and replace TAB with SPACE. E.g. on vim on line + from patch file type x to remove space and not remove sign + and insert space (CTRL) on eqiv to original size.

因为line开始使用TAB istead空间。打开补丁文件,用空格替换TAB。例如,在vim上,从补丁文件类型x删除空格,而不是删除符号+并在eqiv上插入空格(CTRL)以原始大小。

#1


91  

You don't need to care.

你不需要关心。

The warning enacts a standard of cleanliness of text files in regard to whitespace, the kind of thing that many programmers tend to care about. As the manual explains:

该警告在空格处执行了文本文件的整洁标准,这是许多程序员所关心的事情。随着人工解释道:

What are considered whitespace errors is controlled by core.whitespace configuration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.

被认为是空白的错误是由核心控制的。空白的配置。默认情况下,尾随的whitespaces(包括单独由空格组成的行)和一个空格字符,在该行的初始缩进中立即后跟一个制表符,被认为是空格错误。

By default, the command outputs warning messages but applies the patch.

默认情况下,命令输出警告消息,但应用补丁。

So, the "error" means that the change introduces a trailing whitespace, a whitespace-only line, or a space that precedes a tab. Other than that fact, there is nothing erroneous about the change, and it will apply cleanly and correctly. In other words, if you don't care about the "incorrect" whitespace, feel free to ignore the warning or turn it off with git config apply.whitespace nowarn.

因此,“错误”意味着该更改将引入尾随空格、空白行或在选项卡之前的空格。除了这一事实之外,这一变化没有任何错误,它将干净利落地应用。换句话说,如果您不关心“不正确”的空格,可以随意忽略警告或使用git配置关闭它。空格nowarn。

#2


3  

One case when you could legitimately care is when you want to differentiate between "old" whitespase error (that you might want to keep for legacy reason) and "new" whitespace errors (that you want to avoid).

当您想要区分“老”的whitespase错误(您可能希望保留遗留的原因)和“新的”空白错误(您想要避免的)时,您可以合理地关心的一种情况是。

To that effect, 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 Junio in commit 709cd91, 11 Jun 2015)

由Junio C . Hamano (gitster)提交的,提交0e383e1, 0ad782f和d55ef3e[2015年5月26日]。(由Junio于2015年6月11日合并)

diff.c: --ws-error-highlight=<kind> option

Traditionally, 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 of old, new, and context to specify what lines to highlight whitespace errors on.

引入——ws-error-highlight= 选项,允许它们通过一个逗号分隔的旧的、新的和上下文的列表来指定要突出空格错误的行。

The documentation now includes:

现在的文档包括:

--ws-error-highlight=<kind>

Highlight whitespace errors on lines specified by <kind> in the color specified by color.diff.whitespace.
<kind> is a comma separated list of old, new, context.
When this option is not given, only whitespace errors in new 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 for old,new,context.

——ws-error-highlight=new,old强调了删除和添加行中的空格错误。所有这些都可以作为旧的、新的、上下文的缩写。

For instance, the old commit had one whitespace error (bbb), but you can focus on the new errors only (at the end of still bbb and ccc):

例如,旧的commit有一个空格错误(bbb),但是您可以只关注新的错误(在仍然bbb和ccc的末尾):

在应用补丁时,“1行添加空格错误”是什么意思?

(test done after t/t4015-diff-whitespace.sh)

(测试完成后t / t4015-diff-whitespace.sh)

#3


1  

The whitespace error with visual images is shown here.

这里显示了带有可视图像的空格错误。

http://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#Commit-Guidelines

http://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project Commit-Guidelines

#4


-1  

Because line begining with TAB istead of SPACE. Go on patch file and replace TAB with SPACE. E.g. on vim on line + from patch file type x to remove space and not remove sign + and insert space (CTRL) on eqiv to original size.

因为line开始使用TAB istead空间。打开补丁文件,用空格替换TAB。例如,在vim上,从补丁文件类型x删除空格,而不是删除符号+并在eqiv上插入空格(CTRL)以原始大小。