让`git status`忽略空格改动

5

git status 显示我修改了几个文件。但是当我执行以下任何一个参数的 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.

我尝试了git checkout .来重置这些更改,但没有帮助。我该如何将这些文件回滚到原始状态(这样它们就不会再被“修改”),或者永久忽略空格变化,让git status不再显示?

git reset --hard也无效。

2个回答

2

如果您想放弃当前git repo中的所有更改

使用git checkout -- .

如果需要清除未跟踪的文件,请使用git clean -n检查需要清除的文件。

注意:

对于git reset --hard,请非常小心,它会删除所有未提交的文件。更改将永久丢失(无法恢复)。


1
这并没有回答问题。 - Mohammed Rafeeq
@MohammedRafeeq 如果上面提出的“我该如何将这些文件回滚到原始状态(以便它们不再被‘修改’)”问题没有得到回答,请告诉我。 - Vinay Veluri

2

虽然我晚了5年,但是...

当我导出Drupal 8配置(drush cex)时,经常会遇到这种情况。我会立即运行git stash save,然后紧接着运行git stash pop。此时,git status仅报告实际更改的文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接