IDE 1.8.7 changing file with LF characters for newline to CRLF (Windows 7)

I am using Windows 7 (at work) and have just noticed a conflict between files edited on my Windows machine.

I don't recall this happening before I did this recent update to the IDE.

What I would like ( and what I thought the behavior was ) is for the newline characters to be left as they are and for new instances of newline to follow the rest of the file.

What I have found is a single edit such as adding a space to the file and saving the file causes the IDE to rewrite the file and place CRLF on all line endings.

Is there a workaround? Is this a bug in the IDE introduced recently?

Continued digging and found this issue goes back a number of years and is still presenting problems.

In my case I might be able to correct it by reverting to 1.8.5 - according to some comments in github on this issue:

[[update: yes 1.8.5 passed my first tests. My files are 100% LF and the 1.8.6 update broke that by forcing them to 100% CRLF after any edit.

I will need to stay at 1.8.5 unless this gets fixed again in a later version]]

Good work finding the relevant issue report! There was a bug where the IDE would produce inconsistent line endings. The chosen solution was to make them consistent, but fixed according to your OS. Even though I use Windows, I also prefer to use Unix style line endings in all my files. I think the solution proposed by matthijskooijman would be ideal. I think the Arduino developers would be receptive to a patch contributed from the community for this change. Otherwise we can wait and hope they get to it eventually. Unfortunately, I don't think it will be a high priority for them since the current behavior is an improvement over the previous behavior and can't be considered a bug. For now, I just have my Git settings so that all files are committed to my repositories with Unix style line endings. So, even though the sketches on my computer aren't formatted as I prefer, at least I don't subject the rest of the world to Windows style line endings.

what technique do you do to force git to change line endings on the way in?

I found this:

which seems to provide part of what I need in adjusting them on the way out.

I've got to really careful because we use a few different pieces of software and there are a few other users as well.

You got it. I set core.autocrlf to input in all my own repositories. That means it checks out line endings as-is, but commits Unix style line endings.

My global setting is core.autocrlf false because if I’m contributing to someone else’s repository and the file I’m editing has something other than Unix EOL then I don’t want to change the line endings of the file as an unintended side effect of my unrelated edit. If I did want to change their line endings I would do that in a dedicated commit to keep the changes atomic and the diff easily readable.