如何在单个文件中用lf替换crlf [英] How to replace crlf with lf in a single file
问题描述
如何将具有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.
推荐答案
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屋!