文件错误报告修改-git属性错误?导致回购协议不一致

文件错误报告修改-git属性错误?导致回购协议不一致,git,line-endings,Git,Line Endings,这很容易导致git存储库不一致: 如果提交的文件以crlf行结尾,且在工作树中未设置文本属性,但在repo中设置了文本属性,则该文件将错误地显示为已修改 我在Mac(Darwin 13.1.0)上使用Git 1.8.5将core.autocrlf设置为false来复制它 其效果与本问题相同: 您所要做的就是签入一个以CRLF行结尾的文件,在本地为该文件使用与repo中不同的git属性设置 这个小小的shell脚本将从一个干净的repo开始,通过几个简单的步骤生成一个不一致的git存储库 #!/

这很容易导致git存储库不一致: 如果提交的文件以crlf行结尾,且在工作树中未设置文本属性,但在repo中设置了文本属性,则该文件将错误地显示为已修改

我在Mac(Darwin 13.1.0)上使用Git 1.8.5将
core.autocrlf
设置为false来复制它

其效果与本问题相同:

您所要做的就是签入一个以CRLF行结尾的文件,在本地为该文件使用与repo中不同的git属性设置

这个小小的shell脚本将从一个干净的repo开始,通过几个简单的步骤生成一个不一致的git存储库

#!/bin/bash
# creating a git repo "repo"
rm -rf repo
mkdir repo
cd repo
git init
# committing gitattributes with text attribute set for all files
echo "* text" > .gitattributes
git add .gitattributes
git commit -m "added .gitattributes"
# add a file with CRLF line ending with text attribute unset
echo -e "crlf\r" > crlffile
echo "* -text" > .gitattributes
git add crlffile
git commit -m "added crlffile"
git checkout .gitattributes
# now "crlffile" shows as modified, even though it isn't.
# only way to resolve is to modify .gitattributes   
git status crlffile
# crlffile shown as modified.
git checkout crlffile
git status crlffile
# crlffile shown as modified.
git reset --hard
git status
# crlffile shown as modified.
# git diff will report the CR as the difference
git diff 
# but external diff reports no differences.
git difftool --extcmd=diff --no-prompt
问题的实际原因是,我经常在使用msysgit的windows上遇到相同的问题(将
core.autocrlf
设置为false)。似乎egit用户使用eclipse提交文件的方式与这里描述的方式相同,但我试图理解错误是由git还是egit引起的

其他git用户能否尝试在其他平台/版本上复制该问题,并确认/否认这是git bug?

编辑:


如果你认为这个问题在别处已经有了答案,我很想听听答案。“git属性导致了这个问题”并不是这个问题的准确答案。如果这是git bug的一个解决方法,则应将其声明为一个。

可能与@Mikel重复:效果相同,但链接的问题没有提及gitattributes是如何以及是否导致问题的。在我的问题中,人们认为这是罪魁祸首。我的问题还怀疑这是git错误,而不是误用,并给出了如何复制该问题的简单说明。可以在Windows7上使用msysgit使用此shell脚本复制该问题。