如何在单个文件中用lf替换crlf [英] How to replace crlf with lf in a single file

查看:488
本文介绍了如何在单个文件中用lf替换crlf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将具有crlf行返回的单个文件转换为具有lf行返回的文件?

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

git已经正确地自动处理了文件的从crlf到lf的转换,但是在这种情况下,我并没有将其推送到存储库.相反,我正在使用HTML表单上的文件字段将文件上传到要求该文件具有lf行返回的网站.因此,我需要能够单独转换此文件.

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.

我在这台计算机上可用的潜在有用的工具是git和Dreamweaver CC 2014.1. (我猜Word,写字板和记事本不是可行的选项,但我愿意接受更正.)

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.)

我在Windows 7上并使用git line命令.

I am on Windows 7 and using git line commands.

推荐答案

Windows上的git安装通常包括

The git installation on windows usually includes the dos2unix tool.

dos2unix <file>

但是在您的情况下,您应该使用 .gitattributes 来防止文件在窗口.

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

.gitattributes 文件看起来像这样

A .gitattributes file can look like this

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

.git属性文档

设置为字符串值"lf"

此设置强制Git在签入时将行尾规范化为LF,并防止转换为CRLF 当文件签出时.

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

只需提交.gitattributes文件,您的文件将在每个以LF行结尾的系统上检出.

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

这篇关于如何在单个文件中用lf替换crlf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆