解决警告“..LF will be replaced by CRLF the next time Git touches it“

在windows下执行git add . 时出现很多类似如下的警告

复制代码
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pka.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pwr.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rcc.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rng.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rtc.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_sdmmc.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_spi.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_swpmi.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_tim.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usart.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_usb.c', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_utils.c', LF will be replaced by CRLF the next time Git touches it

警告含义是当前工作区里的文件都是"LF"结尾, 但现在Git配置的是core.autocrlf = true

所以下次GIt检出或者重写这些文件时, 会自动把LF转换成CRLF

然后git出现大量的提醒, 就是将来会执行这些转换.

为了不影响代码, 进行如下配置

复制代码
git config --global core.autocrlf false
git config --global core.safecrlf warn

然后统一项目使用 LF 行尾

在项目根目录执行

复制代码
git rm --cached -r . # 清空index
git reset --hard  # 重新checkout所有文件

然后重新执行

复制代码
git status
git add .

warning会全部消失

另外一种方式就是在项目根目录建立.gitattributes文件, 在其中添加

复制代码
* text=auto eol=lf
相关推荐
badhope2 分钟前
Mobile-Skills:移动端技能可视化的创新实践
开发语言·人工智能·git·智能手机·github
zhangfeng11332 小时前
Windows 的 Git Bash 中使用 md5sum 命令非常简单 md5做文件完整性检测 WinRAR 可以计算文件的 MD5 值
人工智能·windows·git·bash
csdn_aspnet10 小时前
Git灾难级误操作抢救手册:从reset到reflog的终极救援
git·恢复·误删
2401_8916558112 小时前
Git + 云原生:如何管理K8s配置版本?
git·云原生·kubernetes
m0_5281744513 小时前
Git对象存储原理(blob/tree/commit) 引用日志(reflog)
大数据·git·elasticsearch·全文检索
无限进步_13 小时前
【C++】单词反转算法详解:原地操作与边界处理
java·开发语言·c++·git·算法·github·visual studio
Wzx19801216 小时前
Git分布式版本控制工具
git
whale fall1 天前
git add、git commit、git push 的区别和联系
git
倾云鹤1 天前
Git同时推送多个远程仓库
git
sdm0704271 天前
基础开发工具git,gdb
git