Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace crlf with lf in a single file

Tags:

git

windows

How do I convert a single file that has crlf line returns to have lf line returns?

git is already correctly handling crlf to lf conversion automatically for files when I push them to a remote repository, but in this particular case I am not doing a push to a repository. Rather, I am uploading a file, using a file field on an HTML form, to a website that requires that the file have lf line returns. So I need to be able to convert this file individually.

My available potentially useful tools available on this computer would be git and Dreamweaver CC 2014.1. (I'm guessing Word, Wordpad and Notepad are not viable options but I'm open to being corrected.)

I am on Windows 7 and using git line commands.

like image 709
Charles Belov Avatar asked Jan 07 '15 02:01

Charles Belov


People also ask

How do I change line ends in notepad?

Converting using Notepad++ To write your file in this way, while you have the file open, go to the Edit menu, select the "EOL Conversion" submenu, and from the options that come up select "UNIX/OSX Format". The next time you save the file, its line endings will, all going well, be saved with UNIX-style line endings.

How do I show CRLF in Notepad ++?

In Notepad++ go to the View > Show Symbol menu and select Show End of Line. Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually.


1 Answers

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.

like image 172
René Link Avatar answered Oct 07 '22 16:10

René Link