5

I and my collegues are having terrible trouble getting git to behave properly with certain files on our Windows repostiory clones. The clones have been made by cloning a repository which originates on an OSX machine. We have set autocrlf to true, but the problem is that we reguarly find files that git thinks are changed even though we never touch them (we don't even open them in an editor.

The following output illustrates the issue: any ideas where I am going wrong?

$ 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                                
#
jkp
  • 70,446
  • 25
  • 98
  • 102

2 Answers2

7

The problem with this settings, as illustrated by the GitHub guide is an automatic conversion is done during the checkout of the repository...

That means you do not need to open a file to trigger any change.

Is it not possible to keep autocrlf to false, and open those Windows files in editors able to respect the return line characters?

Note (illustrated here), if you need the conversion, except for some files, you could add a .gitattributes in the parent directory, with a:

myFile -crlf

In the file you set attributes to a path (or a pattern), or unset them (with the minus sign).
The crlf attribute is the attribute which tells if a file is affected by the core.autocrlf options. If you unset it, Git won’t mess with the line endings in the file

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Great link you posted from Github. So the solution is to commit those files once over and all will be well from then on. Thanks for the pointers. – jkp Jul 30 '09 at 14:01
  • It should be possible for Git to internally handle this without having the end user to configure this right? I'am thinking Git could automatically detect that these differences are due to the how windows and Linux treat line breaks and shouldn't be treated as an actual difference – committedandroider Oct 24 '19 at 21:21
  • 1
    @committedandroider Unfortunately, that is not how Git works by default, which is why I always configured (once) `git config --global core.autocrlf false` – VonC Oct 24 '19 at 21:48
2

To solve this problem on my Windows 7 machine using git 1.7.3.1, I had to set the core.filemode option to false.

git config -e --local
spyle
  • 1,760
  • 21
  • 20
  • 1
    Thanks for this. After messing around with line ending flags for ages. Changing core.filemode in .git/config worked fine. – griffin2000 May 31 '17 at 20:27
  • What's the advantage of having this set to true? I don't get why this flag always be set to false or at least default to false after reading - https://stackoverflow.com/questions/19620335/what-is-gits-filemode - "If false, the executable bit differences between the index and the working tree are ignored" – committedandroider Oct 24 '19 at 21:18