Git CRLF for windows users

Sly picture Sly · Jul 18, 2012 · Viewed 8.1k times · Source

I know that there are tons of articles about this issue. But I'm struggling with it for couple of weeks with no success.

I'm trying to use best practices that are discribed on github. So I added a .gitattributes file, for example it looks like this:

*.cs text

And I've normalized line endings for all files. Now I have clean working copy with nothing to commit. But now if I open a fine in any windows text editor and make some random change, save file, undo that change I see this file as changed. I understand that this is because file now has windows style line endings. But this is horrible way of working, file has no changes and I want git to know about it without git reset --hard. What would you recommend in such case?

Answer

VonC picture VonC · Jul 18, 2012

If you don't want the eol style of your files changed back to windows, don't ask git to perform any "automagic" transformation.
So, contrary to the "best practices from GitHub":

git config --global core.autocrlf true

If you really (I mean really) need one specific set of files in one specific directory to get a particular eol style, add it in your .gitattributes file within said directory, meaning not using text=auto, only "text eol=lf or crlf"