How to replace crlf with lf in a single file

The git installation on windows usually includes the dos2unix tool.

dos2unix <file>

But in your case you should use .gitattributes to prevent the file from being converted on windows.

A .gitattributes file can look like this

*.vcproj    eol=crlf
*.sh        eol=lf

From the .gitattributes documentation

Set to string value “lf”

This setting forces Git to normalize line endings to LF on checkin and prevents conversion to CRLF
when the file is checked out.

Just commit the .gitattributes file and your file will be checkout out on every system with LF line ending.

Leave a Comment