I have a mixed Ubuntu, OS X and Windows git repository containing .bat
and .cmd
files targeted for use on Windows 7 and greater. core.autocrlf
is set to input
, and so post-git checkout
these files have LF
line endings in my working directory instead of the CRLF
line-endings I started out with.
Will this cause problems with windows batch execution? In what cases might this difference be significant? I have yet to see any issue but wish to code defensively.
use a text editor like notepad++ that can help you with understanding the line ends. It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool. you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.
Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character.
They're used to note the termination of a line, however, dealt with differently in today's popular Operating Systems. For example: in Windows both a CR and LF are required to note the end of a line, whereas in Linux/UNIX a LF is only required. In the HTTP protocol, the CR-LF sequence is always used to terminate a line.
Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually. You can then use the menu item Edit > EOL Conversion and select Unix (LF). After selection Edit > EOL Conversion > Unix (LF) your file will be correct for submission.
You can override this for batch files using the following .gitattributes
file:
*.bat text eol=crlf
From Is it safe to write batch files with Unix line endings? There is a comment about labels not working correctly with LF. The fix is easy enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With