The root cause will be boring, so I will put that last if you want to be tortured. But for my rather annoying problem, I tried to code around it. And since it would happen every time I created a new project. Well, I had to dig up the code and run it to fix the problem. This problem is months old for me, may be even a year.
Finally, today I found a very elegant solution. A setting I can put in a file, and I own’t have to deal with it every again for any project. All I had to do was add ‘safecrlf=false’. That was it. I had tried a bunch of other suggestions from time to time and none of them worked.
Lesson, keep it simple. Writing about it now will be the last time I would have to think about how annoying it was.
The root cause for the problem is that developers who are working on windows, would submit files with CRLF ending. CRLF mean ‘carriage-return & line-feed’. Why is that a problem? Well, back in the days of typewriters. Once could do a ‘carriage-return’, which would do two things. Rotate the drum up enough to move to the next line. Here next line really means a new line, and of course slide it over so you can start typing at the beginning of the new line. You could also do a ‘line-feed’, which would just rotate the drum enough for a new line, but it wouldn’t return it to the beginning. This might not seems like something useful. But imagine that you wanted to just travel down the middle of Â page after moving the the desired column. Then all you really wanted was ‘line-feed’. Of course you could turn the drum manually too. But never, all that, that is why there is both ‘carriage-return’ and ‘line-feed’.
Ok, so 99.99% of the people or companies who developed an operating system, used ‘carriage-return’ to mean ‘go to the beginning of a new line’. Microsoft, in their infinite wisdom, use not ‘carriage-return’ or ‘line-feed’, but both. Â Usually, interchanging documents between systems is not a problem. Â A mild annoyance to some non-Windows developers as their text documents have a funny extra character, the ‘line-feed’, at the end of each line. For Windows users, lines won’t wrap as they should, since their system is expecting two characters. But over time, these things became less of a problem, as editors just easily code round the problem.
At first, being the programmer I am, I coded around the problem. Something like this, but in Bash:
while (failing to commit); run dos-to-unix util on failed filed; repeat
I would have to run the code from every project. The code did a lot more than the one liner I showed above. It had to, (a)Â tried to commit a file, (b) see if it failed, (c) extract the file name form the error message, (d) strip out the extra LF character, (e)Â try to commit again. Repeat until all the files can be checked in without complaints from Git. Phew.