GitHub:如何在使用 git 提交时忽略现有的空格?

GitHub: How to ignore existing whitespaces when using git commit?

我修改了一个文件 "index.php",我想第二次应用推送,所以我应用了这些命令:

git add /path/to/index.php

git commit --amend

但我得到了这个结果:

/path/index.php:7: trailing whitespace.

/path/index.php:52: trailing whitespace.

/path/index.php:62: trailing whitespace.

/path/index.php:81: trailing whitespace.

我想要的是提交 忽略那些从一开始就存在的空白在这个文件中,我不想删除它们。

强制提交忽略那些空格

我希望有人对此有解决方案 issue.Thank 你的帮助

我认为您无法使用 git 关闭 warnings/errors。

看看这个答案是有道理的。

Why does git care about trailing whitespace in my files?

你为什么不想删除它们? 保留它们可能会弄乱未来的补丁。

我认为没有任何方法可以忽略 git 中的空白,也不应该有 - 空白是数据,git 跟踪数据的变化,而不是代码。

但是您可以做的是使用 git diff -w 抑制在您的差异中显示空白(以及通过添加 url 参数 ?w= 和 github 差异)

使用--no-verify选项。有人确实费心编写了拒绝看起来像您提交的内容的自定义代码,您确定要这样做吗?