16

I have git on windows configured with git config --global core.autocrlf false so that git does not auto convert files on checkout from LF line endings to CRLF.

When I create a new file on windows and add it I get the following output.

git add windows-file.txt
warning: CRLF will be replaced by LF in windows-file.txt.
The file will have its original line endings in your working directory.

So git is changing my line ending from windows to unix when the windows-file.txt is being added to the git index which is what I want.

The problem I have is that the working directory version is not changed, How can I configure git so that it changes the line endings of both the working directory and the git index?

UPDATE

After the add and the commit git status does not show any differences even though the local working directory version has windows line endings and the repo version has unix line endings.

UPDATE Contents of .gitattributes at the root of the repo

# Set default behaviour, in case users don't have core.autocrlf set.
text eol=lf

# These files are text and should be normalized (convert crlf => lf)
*.java       text
*.xml        text
*.cmd        text
*.sh         text
*.txt        text
*.md         text
*.js         text
*.jsp        text
*.html       text
*.htm        text
*.vm         text
.project     text
.classpath   text
*.properties text
*.txt        text
*.bat        text
*.launch     text

# Denote all files that are truly binary and should not be modified.
*.png    binary
*.jpg    binary
*.jar    binary
*.class  binary
*.gz     binary
*.tar    binary
*.dll    binary
*.exe    binary
*.zip    binary
Zombo
  • 1
  • 62
  • 391
  • 407
ams
  • 60,316
  • 68
  • 200
  • 288
  • Does `git status` show the file being different (i.e. dirty)? – asm Jan 15 '13 at 19:22
  • 1
    `git config --global` changes global setting. It is possible that local, per-repository setting is still in effect. what does `git config core.autocrlf` show? – mvp Jan 15 '13 at 19:22
  • @mvp I am familiar with the local git per repo setting, but set things globbaly because I also use egit which does yet support .gitattributes – ams Jan 15 '13 at 20:08
  • Can you show your `.gitattributes` if you have one? – mvp Jan 15 '13 at 20:20
  • Please refer to this question to force files to use lf: http://stackoverflow.com/questions/2517190/how-do-i-force-git-to-use-lf-instead-of-crlf-under-windows – stormwild Feb 03 '16 at 09:27
  • Possible duplicate of [How do I force git to use LF instead of CR+LF under windows?](http://stackoverflow.com/questions/2517190/how-do-i-force-git-to-use-lf-instead-of-crlf-under-windows) – Lorenz Meyer Mar 13 '17 at 12:49

1 Answers1

19

When you have no uncommitted changes try:

git rm --cached -r . 
git reset --hard

to remove the local files and get them from the index.

laktak
  • 57,064
  • 17
  • 134
  • 164