2014-11-25 71 views
0

当我做git status我看到这一点:`git的status`和EOL检测

Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     modified: project/schema-readme.md 
     modified: project/vp-automate.php 

奇怪的是,这两个文件是实际修改 - 它们是二进制相同,逐字节。

现在我认为我知道他们为什么打上了混帐的修改:这是因为他们使用的CRLF行结束,而我们的项目最近增加了一个.gitattributes文件与此内容:

* text=auto eol=lf 

这应该意味着当承诺时,Git会实际更新它们以使LF行结束。那么为什么git status将这些文件标记为“已修改”,即使它们当前未被修改?

编辑:这是奇怪的,也有在我的项目更多的文件使用CRLF行结束和修改不检测。我不明白什么特别之处schema-readme.mdvp-automate.php了Git检测它们进行修改。

回答

1

除SHA1校验和外,Git还根据某些文件属性检测到更改的文件,这可能会导致这两个文件被标记为已更改。有关Git如何检测文件更改的更多信息,请参阅answer to this question

0

请尝试配置core.autoccrlf属性。它主要用于Windows机器上,以确保本地文件使用CRLF作为行结束符(因此它们可以在记事本等中使用),而存储库中的“内部”文件则保留“合适的”LF结尾。

从文档(混帐配置--help):

core.autocrlf 
     Setting this variable to "true" is almost the same as setting the text attribute to "auto" on all files except that text files are not guaranteed to be normalized: files that contain CRLF in the repository will not be touched. Use this setting if you want to have CRLF line endings in 
     your working directory even though the repository does not have normalized line endings. This variable can be set to input, in which case no output conversion is performed. 

另见https://help.github.com/articles/dealing-with-line-endings#platform-all - 如建议,在Linux上,你应该将其配置为 “输入”。

+0

事情是我不想CRLF - 由于各种原因,我们甚至需要在Windows上使用LF。这个问题完全是关于为什么Git检测到一些未更改的文件已更改以及是否与行尾有关。 – Borek 2014-11-25 14:50:41