[git] warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF
2015-11-18 11:22
302 查看
遇到这两个错误,是因为Git的换行符检查功能。
建议使用最严格的
Git可以在你提交时自动地把行结束符CRLF转换成LF,而在签出代码时把LF转换成CRLF。用
Linux或Mac系统使用LF作为行结束符,因此你不想 Git 在签出文件时进行自动的转换;当一个以CRLF为行结束符的文件不小心被引入时你肯定想进行修正,把
Git 在提交时把CRLF转换成LF,签出时不转换:
这样会在Windows系统上的签出文件中保留CRLF,会在Mac和Linux系统上,包括仓库中保留LF。
如果你是Windows程序员,且正在开发仅运行在Windows上的项目,可以设置
core.safecrlf
Git提供了一个换行符检查功能(core.safecrlf),可以在提交时检查文件是否混用了不同风格的换行符。这个功能的选项如下:
false- 不做任何检查
warn- 在提交时检查并警告
true- 在提交时检查,如果发现混用则拒绝提交
建议使用最严格的
true选项。
core.autocrlf
假如你正在Windows上写程序,又或者你正在和其他人合作,他们在Windows上编程,而你却在其他系统上,在这些情况下,你可能会遇到行尾结束符问题。这是因为Windows使用回车和换行两个字符来结束一行,而Mac和Linux只使用换行一个字符。虽然这是小问题,但它会极大地扰乱跨平台协作。Git可以在你提交时自动地把行结束符CRLF转换成LF,而在签出代码时把LF转换成CRLF。用
core.autocrlf来打开此项功能,如果是在Windows系统上,把它设置成
true,这样当签出代码时,LF会被转换成CRLF:
<code style="margin-right: 0px; margin-left: 0px; padding: 0px; white-space: pre; border: none; border-radius: 3px; margin-top: 0px !important; margin-bottom: 0px !important; background-color: transparent;"><span class="pln" style="color: rgb(240, 240, 240); margin-top: 0px !important;">$ git config </span><span class="pun" style="color: rgb(139, 137, 112);">--</span><span class="kwd" style="color: rgb(132, 112, 255);">global</span><span class="pln" style="color: rgb(240, 240, 240);"> core</span><span class="pun" style="color: rgb(139, 137, 112);">.</span><span class="pln" style="color: rgb(240, 240, 240);">autocrlf </span><span class="kwd" style="color: rgb(132, 112, 255); margin-bottom: 0px !important;">true</span></code>
Linux或Mac系统使用LF作为行结束符,因此你不想 Git 在签出文件时进行自动的转换;当一个以CRLF为行结束符的文件不小心被引入时你肯定想进行修正,把
core.autocrlf设置成input来告诉
Git 在提交时把CRLF转换成LF,签出时不转换:
<code style="margin-right: 0px; margin-left: 0px; padding: 0px; white-space: pre; border: none; border-radius: 3px; margin-top: 0px !important; margin-bottom: 0px !important; background-color: transparent;"><span class="pln" style="color: rgb(240, 240, 240); margin-top: 0px !important;">$ git config </span><span class="pun" style="color: rgb(139, 137, 112);">--</span><span class="kwd" style="color: rgb(132, 112, 255);">global</span><span class="pln" style="color: rgb(240, 240, 240);"> core</span><span class="pun" style="color: rgb(139, 137, 112);">.</span><span class="pln" style="color: rgb(240, 240, 240); margin-bottom: 0px !important;">autocrlf input</span></code>
这样会在Windows系统上的签出文件中保留CRLF,会在Mac和Linux系统上,包括仓库中保留LF。
如果你是Windows程序员,且正在开发仅运行在Windows上的项目,可以设置
false取消此功能,把回车符记录在库中:
<code style="margin-right: 0px; margin-left: 0px; padding: 0px; white-space: pre; border: none; border-radius: 3px; margin-top: 0px !important; margin-bottom: 0px !important; background-color: transparent;"><span class="pln" style="color: rgb(240, 240, 240); margin-top: 0px !important;">$ git config </span><span class="pun" style="color: rgb(139, 137, 112);">--</span><span class="kwd" style="color: rgb(132, 112, 255);">global</span><span class="pln" style="color: rgb(240, 240, 240);"> core</span><span class="pun" style="color: rgb(139, 137, 112);">.</span><span class="pln" style="color: rgb(240, 240, 240);">autocrlf </span><span class="kwd" style="color: rgb(132, 112, 255); margin-bottom: 0px !important;">false</span></code>
相关文章推荐
- children和childNodes 的区别
- oracle创建表
- (干货分享)农商行中商业智能建设的整体思路与架构
- iOS调用系统相册、相机界面语言设置为中文
- STM32使用J-Link下载出错解决方法。
- ViewPager 详解(三)---PagerTabStrip与PagerTitleStrip添加标题栏的异同
- php+ajax实现无刷新分页
- 系统架构补充
- 关于安卓 TextView 添加点击事件
- (干货分享)农商行中商业智能建设的整体思路与架构
- 最全行内元素和块级元素分类
- [置顶] 国内首部Java多线程设计模式原创作品《Java多线程编程实战指南(设计模式篇)》已出版
- [置顶] 通过心理学知识提高问题定位与解决能力(上)
- [置顶] Java多线程编程模式实战指南(三):Two-phase Termination模式
- [置顶] Java多线程编程模式实战指南(二):Immutable Object模式
- [置顶] Java多线程编程模式实战指南(一):Active Object模式(下)
- [置顶] 敏捷项目管理实战之在敏捷开发中引入 Story 演示
- [置顶] Linux下恢复被误删除的syslog—/var/log/messages
- 理解MySQL——索引与优化
- IconFont 图标