17

这是我的系统对话:

unrollme-dev-dan:views Dan$ git reset --hard HEAD
HEAD is now at 3f225e9 Fix scan titles
unrollme-dev-dan:views Dan$ git status
# On branch master
# 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:   app/signup/finish.html
#   modified:   app/signup/scan.html
#

我将 autocrlf 设置为 false:

unrollme-dev-dan:unroll-website Dan$ git config core.autocrlf
unrollme-dev-dan:unroll-website Dan$ 
unrollme-dev-dan:unroll-website Dan$ git config --global core.autocrlf
unrollme-dev-dan:unroll-website Dan$

而且我没有任何 .gitattributes 文件搞砸了:

unrollme-dev-dan:unroll-website Dan$ find . -name .gitattributes
[ only results are in different directory tree ]

这是由.gitattributes下面的答案中指出的一个级别引起的。

当我od -c对它显示的文件执行操作时\r\n。我不知道他们“应该”是什么,大概他们应该以什么结尾,\n这就是差异显示的原因。但我不明白的是,即使是autocrlf假的,这些文件也可能在结账时被修改。

除了 autocrlf 之外,还有什么会导致 git 在结帐时修改文件?

4

2 回答 2

20

这个问题可能是由 gitattributes 的文本选项引起的 https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

.gitattributes可以通过临时编辑项目文件夹中的文件来解决此问题。

更改* text=auto#* text=auto对文件行结尾进行必要的更改并推送您的提交。然后,您可以在进行更改后再次启用它,或者选择可能更适合您的项目的其他选项之一。

于 2013-03-28T16:52:23.063 回答
4

我没有接受的答案中提到的 gitattributes 文件,在我的情况下这是一个文件权限问题。要查看这是否是您的问题,请使用 git diff 检查更改的文件的差异,例如:

git diff path/to/file.html

如果您看到的唯一更改是旧模式/新模式,则可能是权限问题。您可以使用以下命令告诉 git 忽略文件权限更改:

git config core.filemode false

或者

git config --global core.filemode false

(取决于你如何使用 git)。

出于性能原因,我最近从使用 Cygwin git 切换到 Windows 的 git,另外为了 TortoiseGit 可以正常工作,这可能是我的情况下权限被丢弃的原因。

参考:

  1. 如何从 Git 中的未暂存更改中删除说“旧模式 100755 新模式 100644”的文件?
于 2015-05-14T15:51:25.087 回答