1

I develop and use Git on both Windows and Linux. When using IDEs or Git on Windows, I'm frequently prompted on whether to save files with CR LF or not.

I am doing mainly C# and JavaScript ES6 development which involves code that contains multi-line strings.

What reasons are there to save files with CR LF on Windows? Are CR-LFs mostly of historical significance? I have not yet noticed a drawback to working with UNIX \n line endings on Windows.

Community
  • 1
  • 1
T. Webster
  • 9,605
  • 6
  • 67
  • 94
  • CR+LF is the correct way, LF is just a lazy shortcut Unix inherited. Unless there's a reason not to (like working with Linux scripts), always using CR+LF is generally best. – InterLinked Apr 15 '20 at 14:49

2 Answers2

2

Some Windows programs don't properly handle '\n' without '\r' but any decent editor or for that matter any decent program should handle them identically. But CRLF is traditionally the sanctioned way to do line endings on Windows and you might have compatibility issues if you don't.

kcraigie
  • 1,252
  • 6
  • 13
  • could you please be more specific on where there might be compatibility issues, like with what specific programs, traditional or non-. – T. Webster May 21 '16 at 00:11
  • For example, Notepad.exe doesn't handle UNIX line endings on Windows XP. – kcraigie May 21 '16 at 00:13
  • my question has been edited to be more specific about which version of Windows I intended the question for. Do you see any compatibility issues with UNIX endings on Windows >= 8.1? – T. Webster May 21 '16 at 00:43
  • I really think it depends on the situation. If you're writing .txt files on Windows, I'd play it safe with CRLF. Otherwise go with whatever file format specification applies to what you're writing. – kcraigie May 21 '16 at 00:50
2

Windows batch files can malfunction when saved with newline endings because the goto command works by jumping to the appropriate offset in the script — but it is not computed correctly unless the lines end with carriage-return/line-feed.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105