我现在遇到了一个存储库问题,虽然我的git-fu通常很好,但我似乎无法解决这个问题.
当我克隆这个存储库,然后cd进入repo时,git-status会显示几个已更改的文件.注意:我没有在任何编辑器或任何东西中打开回购.
我尝试按照本指南:http://help.github.com/dealing-with-lineendings/但这对我的问题没有任何帮助.
我尝试了cd很多次,但似乎没有做任何事情.
任何帮助/想法将不胜感激
更新1:我在Mac上,并且repo本身没有子模块.
更新2:文件系统是mac上的"Journaled HFS +"文件系统,不区分大小写.这些文件是一行的,每个大约79K(是的,你听到了),所以看看git status并不是特别有用.我听说过git checkout -- .这可能会有所帮助,当我回到计算机上时,我会尝试使用它.
更新3:用事实更改文件系统的细节!而且,我尝试了git diff一些效果不佳的技巧.
adn*_*ans 139
克隆回购后我在Mac上遇到了同样的问题,它会假设所有文件都已更改.
运行后,git config --global core.autocrlf input它仍然将所有文件标记为已更改.在寻找修复后,我遇到.gitattributes了主目录中的文件,其中包含以下内容.
* text=auto
Run Code Online (Sandbox Code Playgroud)
我评论了它,从现在开始任何其他克隆的存储库工作正常.希望这可以帮助那里的任何人.
Sam*_*ott 88
我知道了.所有其他开发人员都在ubuntu(我认为),因此具有区分大小写的文件系统.但是,我没有(因为我在Mac上).事实上,当我使用它们时,所有文件都有小写双胞胎git ls-tree HEAD <path>.
我会让他们中的一个来解决它.
Pio*_*aga 63
git config core.fileMode false
Run Code Online (Sandbox Code Playgroud)
在我的情况下解决了这个问题
https://www.kernel.org/pub/software/scm/git/docs/v1.7.10.1/git-config.html
TL; DR;
core.fileMode
如果为false,则忽略索引和工作树之间的可执行位差异; 对像FAT这样的破碎文件系统很有用.请参阅git-update-index(1).
默认值为true,但git-clone(1)或git-init(1)将在创建存储库时探测并设置core.fileMode false.
Arr*_*ter 52
我假设您使用的是Windows.您链接的github页面具有向后的详细信息.问题是CRLF行结尾已经提交到repo,因为你将core.autocrlf设置为true或者输入,git想要将行结尾转换为LF,这样就git status表明每个文件都被更改了.
如果这是您只想访问但没有参与的回购,则可以运行以下命令来隐藏问题而不实际解决问题.
git config core.autocrlf false
Run Code Online (Sandbox Code Playgroud)
以下内容直接来自gitattributes手册页,应该从干净的工作目录中执行.
echo "* text=auto" >>.gitattributes
rm .git/index # Remove the index to force Git to
git reset # re-scan the working directory.
git status # Show files that will be normalized.
git add -u
git add .gitattributes
git commit -m "Introduce end-of-line normalization"
Run Code Online (Sandbox Code Playgroud)
如果任何不应规范化的文件显示为git status,请在运行前取消设置其text属性git status.
manual.pdf -text
Run Code Online (Sandbox Code Playgroud)
相反,git未检测到的文本文件可以手动启用规范化.
weirdchars.txt text
Run Code Online (Sandbox Code Playgroud)
kds*_*kds 36
请运行以下命令.这可能会解决问题.
# Remove everything from the index.
git rm --cached -r .
# Write both the index and working directory from git's database.
git reset --hard
Run Code Online (Sandbox Code Playgroud)
J A*_*ers 16
在Visual Studio中,如果您使用的是Git,则可以自动生成.gitignore和.gitattributes文件.自动生成的.getattributes文件包含以下行:
* text=auto
Run Code Online (Sandbox Code Playgroud)
此行靠近文件的顶部.我们只需要在前面添加一个#来评论该行.在这之后,事情按预期运作.
Gim*_*ima 12
问题也可能来自不同的文件权限,我的情况也是如此:
新鲜的克隆存储库(Windows,Cygwin):
$ git ls-tree HEAD
100755 blob 8099ea496a2c78d71125d79a05855f60ebf07904 testfile
???
Run Code Online (Sandbox Code Playgroud)
裸露的远程存储库(Linux):
$ git ls-tree HEAD
100644 blob 8099ea496a2c78d71125d79a05855f60ebf07904 testfile
???
Run Code Online (Sandbox Code Playgroud)
对我来说同样的问题。我可以在远程 Git 存储库中看到多个具有相同名称的图像,例如“textField.png”和“textfield.png”,但在本地存储库中却看不到。我只能看到项目代码中未使用的“textField.png”。
事实证明,我的大多数同事都在使用ext4文件系统的 Ubuntu 上,而我在使用 APFS 的 Mac 上。
感谢Sam Elliott的回答,解决方案非常简单。首先我让Ubuntu上的同事删除大写的冗余文件版本,然后远程提交和推送。
然后我运行了以下命令:
# Remove everything from the index.
git rm --cached -r .
# Write both the index and working directory from git's database.
git reset --hard
Run Code Online (Sandbox Code Playgroud)
最后,我们决定每个开发人员都应该更改他的 Git 配置,以防止这种情况再次发生:
# Local Git configuration
git config core.ignorecase true
Run Code Online (Sandbox Code Playgroud)
或者
# Global Git configuration
git config --global core.ignorecase true
Run Code Online (Sandbox Code Playgroud)
我想添加一个针对“为什么”发生的答案,因为已经有一个很好的解决方法。
因此,.gitattributes有一个* text=auto设置,导致此问题。
就我而言,GitHub的master分支上的文件以\r\n结尾结尾。我已经拨出存储库上的设置以签入\n结尾。我不知道Git会检查什么。应该在本机Linux框(\n)上签出带有本机结尾的文件,但我想它签出了带\r\n结尾的文件。Git抱怨是因为它看到\r\n存储库中已签出的结尾,并警告我它将签入\n设置。因此,文件被“修改”。
这是我目前的理解。