Git提交代码时出现: ‘LF will be replaced by CRLF the next time Git touches it‘

遇到的问题

windows平台进行 git add 时,控制台打印警告

问题分析

1. Dos/Windows平台默认换行符:回车(CR)+换行(LF),即’\r\n’

2. Mac/Linux平台默认换行符:换行(LF),即’\n’ 

企业服务器一般都是Linux系统进行管理,所以会有替换换行符的需求

解决方法

设置方法一:

#提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf true

适用于Windows系统,且一般为Windows默认设置,会在提交时对换行符进行CRLF - LF的转换,检出时又会进行LF - CRLF的转换。

设置方法二:

#提交时转换为LF,检出时不转换
git config --global core.autocrlf input

*适用于Linux系统,所有换行符都会进行CRLF - LF转换,但操作时不会转换回CRLF。

参考文章:Git: ‘LF will be replaced by CRLF the next time Git touches it‘ 问题解决与思考-CSDN博客

你可能感兴趣的:(git)