I'm on Windows and I have core.autocrlf
disabled:
$ git config core.autocrlf; git config --global core.autocrlf
false
false
Now, I would assume, that git does not mess with any line endings, but some files in my repo keep causing issues.
I just cloned a fresh copy of the repo, and git is already telling me that there are unstaged changes. When I git diff -R
, I can see that CRLF line endings have been added to a file:
diff --git b/nginx-1.11.1/contrib/geo2nginx.pl a/nginx-1.11.1/contrib/geo2nginx.pl
index bc8af46..29243ec 100644
--- b/nginx-1.11.1/contrib/geo2nginx.pl
+++ a/nginx-1.11.1/contrib/geo2nginx.pl
@@ -1,58 +1,58 @@
-#!/usr/bin/perl -w
-
-# (c) Andrei Nigmatulin, 2005
+#!/usr/bin/perl -w^M
+^M
+# (c) Andrei Nigmatulin, 2005^M
I don't understand where these line endings come from, but I'm also unable to "revert" this change. When I checkout the file again, it will still be modified afterwards:
$ git checkout -f nginx-1.11.1/contrib/geo2nginx.pl
$ git status
On branch dev
Your branch is up-to-date with 'origin/dev'.
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: nginx-1.11.1/contrib/geo2nginx.pl
no changes added to commit (use "git add" and/or "git commit -a")
This makes no sense to me, so I just run dos2unix
on the file:
$ dos2unix nginx-1.11.1/contrib/geo2nginx.pl
dos2unix: converting file nginx-1.11.1/contrib/geo2nginx.pl to Unix format...
Now there surely shouldn't be any changes, right? But the file is still being shown as modified in git status
and git diff
will still report CRLF line endings in the working copy.
When I now stage and commit the file, the resulting file will have LF line endings, even though the diff showed CRLF line endings.
I don't have a global .gitattributes
(git config --global core.attributesfile
does not output anything). And the .gitattributes
in the project has * text eol=lf
set (full .gitattributes
).
What is going on here and how can I resolve this?
Reproduce the issue
I can repro this issue with an open source project I'm maintaining:
$ git clone [email protected]:fairmanager/fm-log.git
Cloning into 'fm-log'...
remote: Counting objects: 790, done.
remote: Total 790 (delta 0), reused 0 (delta 0), pack-reused 790
Receiving objects: 100% (790/790), 201.71 KiB | 138.00 KiB/s, done.
Resolving deltas: 100% (418/418), done.
Checking connectivity... done.
$ cd fm-log/
$ git status
On branch master
Your branch is up-to-date with 'origin/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: .idea/dictionaries/OliverSalzburg.xml
modified: .idea/inspectionProfiles/Project_Default.xml
modified: .idea/inspectionProfiles/profiles_settings.xml
no changes added to commit (use "git add" and/or "git commit -a")
See Question&Answers more detail:
os