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

时间:2014-04-02 21:04:23

标签: git line-endings

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

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

效果与此问题相同: Git files modified after checkout, reset --hard, etc. even though autocrlf is set to false

您所要做的就是使用CRLF行结尾签入文件,在本地使用与文件不同的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的窗口上遇到同样的问题(core.autocrlf设置为false)。似乎使用eclipse的egit用户按照这里描述的方式提交文件,但我试着理解错误是由git还是egit引起的。

其他git用户可以尝试用其他平台/版本复制问题并确认/否认这是一个git bug吗?

编辑:

如果你认为这个问题在其他地方已有答案,我会有兴趣听到答案。 " git属性导致问题"对这个问题来说,答案不够准确。如果它是git bug的解决方法,则应将其声明为一个。

0 个答案:

没有答案