处理Git拒绝重置的文件?

6
我和同事们在Windows上复制了一个源自OSX机器的代码库并设置了autocrlf为true,但是我们发现有些文件 git 会认为被更改了,即使我们从未触碰它们(甚至没有打开编辑器)。以下输出展示了这个问题:你有什么想法吗?
$ git status                                                                                                 
# On branch master                                                                                           
# Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.                            
#                                                                                                            
# Changed but not updated:                                                                                   
#   (use "git add <file>..." to update what will be committed)                                               
#   (use "git checkout -- <file>..." to discard changes in working directory)                                
#                                                                                                            
#       modified:   Web Applications/webclient/language/en/lang_copyitems.ini                                
#                                                                                                            
no changes added to commit (use "git add" and/or "git commit -a")                                            

Administrator@windows-dev ~/Documents/Workspace/prestige.git                                                 
$ git diff "Web Applications/webclient/language/en/lang_copyitems.ini"                                       
diff --git a/Web Applications/webclient/language/en/lang_copyitems.ini b/Web Applications/webclient/language/
index 800c188..ed11c0e 100644                                                                                
--- a/Web Applications/webclient/language/en/lang_copyitems.ini                                              
+++ b/Web Applications/webclient/language/en/lang_copyitems.ini                                              
@@ -1,12 +1,12 @@                                                                                            
-<EF><BB><BF>   [Header]                                                                                     
-       Description=Language strings for 'copyitems.php'                                                     
-                                                                                                            
-       [Messages]                                                                                           
-       300=Copy                                                                                             
-       301=Close                                                                                            
-       302=COPY STORIES                                                                                     
-       303=Name                                                                                             
-       304=In Queue                                                                                         
-       305=New Name                                                                                         
-       306=Items to Copy                                                                                    
-       308=This item has mandatory metadata fields that are not correctly set. Click any part of this messag
+<EF><BB><BF>   [Header]                                                                                     
+       Description=Language strings for 'copyitems.php'                                                     
+                                                                                                            
+       [Messages]                                                                                           
+       300=Copy                                                                                             
+       301=Close                                                                                            
+       302=COPY STORIES                                                                                     
+       303=Name                                                                                             
+       304=In Queue                                                                                         
+       305=New Name                                                                                         
+       306=Items to Copy                                                                                    
+       308=This item has mandatory metadata fields that are not correctly set. Click any part of this messag

Administrator@windows-dev ~/Documents/Workspace/prestige.git                                                 
$ git checkout HEAD "Web Applications/webclient/language/en/lang_copyitems.ini"                              

Administrator@windows-dev ~/Documents/Workspace/prestige.git                                                 
$ git status                                                                                                 
# On branch master                                                                                           
# Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.                            
#                                                                                                            
# Changed but not updated:                                                                                   
#   (use "git add <file>..." to update what will be committed)                                               
#   (use "git checkout -- <file>..." to discard changes in working directory)                                
#                                                                                                            
#       modified:   Web Applications/webclient/language/en/lang_copyitems.ini                                
#
2个回答

8
这个设置存在问题,正如GitHub指南所示,当仓库checkout时会自动转换...
这意味着您不需要打开文件来触发任何更改。
不可能保持autocrlf为false,然后在能够尊重回车符的编辑器中打开这些Windows文件吗?
请注意(在此处说明),如果您需要进行转换,除了某些文件,您可以在父目录中添加一个.gitattributes文件,其中包含:
myFile -crlf

在文件中,您可以为路径(或模式)设置属性,或使用减号取消它们。

crlf 属性是告诉 Git 文件是否受 core.autocrlf 选项影响的属性。如果您取消设置它,Git 将不会干扰文件中的行尾。


你在Github上发布的链接很棒。所以解决方案是一次性提交这些文件,从那时起一切都会好起来。感谢你的指引。 - jkp
Git应该可以在不需要最终用户配置的情况下内部处理这个问题,对吧?我想Git可以自动检测到这些差异是由于Windows和Linux处理换行符的方式而产生的,并且不应被视为实际差异。 - committedandroider
1
@committedandroider 很遗憾,这不是 Git 的默认工作方式,这就是为什么我总是配置(一次)git config --global core.autocrlf false - VonC

2

在我的Windows 7机器上使用git 1.7.3.1解决此问题,我必须将core.filemode选项设置为false。

git config -e --local

1
谢谢。在折腾了很长时间的行尾标志后,更改.git/config中的core.filemode就可以了。 - griffin2000
将此设置为true的优点是什么?我不明白为什么这个标志总是被设置为false,或者至少在阅读https://dev59.com/oGIk5IYBdhLWcg3wE6Z8之后默认为false - “如果为false,则忽略索引和工作树之间的可执行位差异”。 - committedandroider

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接