This line endings problem is driving me nuts...
Background: Historically, I was using the core.autocrlf setting but I found I had problems with different repos behaving badly (I work on Windows and I have some repos that require LF endings and some that require CRLF endings). So I am trying to move away from that and use a .gitattributes in each repository (I want Git to just shut up and let me manage line endings!). So I now have core.autocrlf=false
and a .gitattributes
that looks like this for a Visual Studio project I am working on:
# Don't do any end of line normalization.
* -text
# Always treat these files as binary. Not strictly necessary, but can't hurt.
*.png binary
*.gif binary
*.jpg binary
*.jpeg binary
*.dll binary
*.doc binary
*.docx binary
*.xls binary
*.xlsx binary
*.pdf binary
I have forced all the files in the repo to CRLF endings with unix2dos and confirmed that they have the right line endings in the working directory, and checked them all in. And yes I followed the advice here Trying to fix line-endings with git filter-branch, but having no luck
This is almost perfect.
THE PROBLEM is that whenever I change a file git reports that it has line ending differences on the changed lines, for example, if the original line is
string s;
and the changed line is
string sucks;
git diff shows the change as
string sucks;^M
It looks like Git thinks that the files in the repo still have LF endings (because they were normalized in the past?). The ^M cause a large amount of visual noise and I am not sure whether this is a symptom of anything else. I don't understand why Git is reporting a difference because I have checked in all the files with CRLF endings in a previous commit, in fact the commit just before this one.
So why am I getting these "fake" differences and how can I get rid of them?