8

从...开始

git status
# On branch master
nothing to commit, working directory clean

然后切换到另一个分支

git checkout somebranch

切换到新分支并运行git statusgit 后,有时会抱怨随机更改的文件。如果我用它来区分文件,git diff它将首先显示整个文件,所有行都被删除,然后再次添加

- someline
- someotherline
+ someline
+ someotherline

然后运行 ​​agit diff --ignore-space-at-eol .将不会显示任何文件已更改,这使我相信 git repo 中的某处存在行尾问题,因为如果我使用我选择的合并工具(Beyond Compare)对文件进行二进制比较,它会告诉我文件是二进制相同,即使 git 抱怨它们不同,地狱我什至做了一个十六进制比较,它们确实是相同的,那么为什么 git 认为它们改变了?

该存储库位于旧 svn 存储库上,该存储库按照 github 指南https://help.github.com/articles/importing-from-subversion进行转换,之后我们将 .gitattributes 文件添加到解决方案中,如下所示:

# .gitattributes
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp
*.sln    merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc    diff=astextplain
*.DOC    diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF    diff=astextplain
*.rtf    diff=astextplain
*.RTF    diff=astextplain

添加 .gitattributes 文件后,我们还按照 githubs 指南从https://help.github.com/articles/dealing-with-line-endings修复行尾

团队中的每个人都在 windows 上运行,团队中的每个人都在使用 core.autocrlf=true 并且每个人都在使用至少

git --version
git version 1.8.3.msysgit.0

这里有什么问题?git 抱怨的文件是完全随机的,它发生在团队中的每个人身上。此外,使用 git checkout file-that-hasnt-really-changed 也无法恢复它抱怨的文件。

4

2 回答 2

5

在我的仓库中添加由 Visual Studio 生成的默认 .gitattributes 文件后,我遇到了同样的问题。您可以通过在 .gitattributes 中注释掉以下行来修复它:

# * text=auto

仅提交此文件,所有其他虚假更改的文件现在将从您的本地更改列表中消失。

注意: auto 选项指示 git 存储所有以 LF 行内部结尾的文件。当您签出文件时,行尾将转换回 CRLF,因此我们运行 git diff 它会看到来自仓库的 LF 和来自签出版本的 CRLF 之间的差异。对我来说似乎是一个错误。

于 2014-02-17T03:57:37.060 回答
-1

First of all, don't mix an old scheme (core.autocrlf) and the new one (.gitattributes).

To fix the problematic files locally you can do the following:

git rm --cached -r .
git reset --hard
于 2013-11-17T15:34:52.363 回答