3

使用 Ubuntu 时,我的所有文件都在 Git 中未暂存。

当我运行时git diff,Git 显示:

--- a/<filename>
+++ b/<filename>
-<output of file>
+<output of file>

例如,

--- a/.gitignore
+++ b/.gitignore
-.tmp
-build
-node_modules
+.tmp
+build
+node_modules

但是,当我在 Windows 中使用 Git 时,Git 会正确显示状态(所有文件已提交和暂存)

关于如何解决这个问题的任何想法?

我在 Ubuntu 和 Windows 中使用与 Git repo 相同的分区,并且由于它是 FAT32,Ubuntu 会自动挂载该分区。

4

1 回答 1

3

This sounds like a CRLF issue. Windows uses CRLF to denote end-of-line while Linux uses just LF. Git uses just LF natively. When you switch from Windows to Linux, git sees the files as changed because it doesn't think it has to convert the CRLF that ends every line to LF and thus the files get extra CR characters.

See this blog post on the subject for an extensive discussion.

This is all controlled by the core.eol config option. Typically, this is set to native, which tells git to use your OSes EOL convention. Your best bet is to create a .gitattributes file as the post specifies, telling get to use LF regardless of the OS.

于 2013-08-28T06:11:54.647 回答