Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...