Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

windows - How to replace crlf with lf in a single file

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...