git 添加 .修改所有项目

git add . modifying all the project

git add . 应该添加新的和修改过的文件。我确实只更改了 2 个文件,当我使用 运行 git status 命令时,它显示整个项目都已修改。可能是什么问题?谢谢

您是否尝试使用 git diff 来查看进行了哪些修改,它有时可能是 ide,您的使用可能会导致文件中出现某些格式。

正如@Oliver 在评论中提到的,它看起来像是行尾差异。

为了帮助您解决这个问题,我想引用两个答案:

首先来自 here 如何在 git diff 中显示行尾差异:

First, make sure you're using the coloured output (e.g. with git diff --color) and that you've enabled whitespace highlighting with (e.g.)

git config color.diff.whitespace "red reverse"

This might not work in all cases, however, as git doesn't appear to highlight trailing whitespace for removed lines. To see whitespace that you've deleted, simply use

git diff -R

to put the whitespace on the 'added' side of the comparison, where it does get highlighted.

For more detail, see the answers at this SO question.

here 中关于如何解决行尾问题的第二个

GitHub suggests that you should make sure to only use \n as a newline character in git-handled repos. There's an option to auto-convert:

$ git config --global core.autocrlf true

Of course, this is said to convert crlf to lf, while you want to convert cr to lf. I hope this still works …

注意:请参考原始 question/answers 以确保它们符合您的需要,因为 git 存储库通常包含无价的数据并且弄乱它们不是一个好主意,除非您知道自己在做什么。