Skip to content
📈0️⃣

git push 时警告 LF will be replaced by CRLF the next time Git touches it

git push时警告LF will be replaced by CRLF the next time Git touches it

报错如下:

sh
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/3.Vue 进阶/9.组合式 API/1. setup.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/3.Vue 进阶/9.组合式 API/2.响应式-核心 API.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/3.Vue 进阶/9.组合式 API/3.响应式-工具 API.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/3.Vue 进阶/9.组合式 API/4.响应式-进阶 API.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/3.Vue 进阶/9.组合式 API/5.生命周期钩子.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/5.Vue 实战/2.DevTools/1.DevTools简介.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/5.Vue 实战/2.DevTools/2.Chrome安装DevTools插件.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/9.Vue 源码解析/0.源码分析.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/9.Vue 源码解析/1.mount 挂载实例.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/99.其他/1.vue2 前端跨域解决方案之proxy代理.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/1.Vue/99.其他/2.VueCLI 脚手架配置代理服务器解决跨域.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/2.ES6/1.ES6/1.ES6简介.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/2.ES6/2.WebAPI概念/0.WebAPI简介.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'blog/docs/.vitepress/dist/2.ES6/2.WebAPI概念/1.DOM API(Document Object Model API).html', LF will be replaced by CRLF the next time Git tou
warning: in the working copy of 'blog/docs/.vitepress/dist/2.ES6/4.js全局函数/0.js全局函数.html', LF will be replaced by CRLF the next time Git touches it

原因

在 windows 下,换行符为\r\n,而在 linux 下,换行符为\n,在提交时,git 会自动将\r\n转换为\n,而当 git 在 windows 下提交时,会将\n转换为\r\n,从而导致LF will be replaced by CRLF the next time Git touches it的警告。

这些警告信息表示在工作副本中的一些文件,下一次 Git 操作时,换行符 LF 将被替换为 CRLF。这是因为 Git 默认使用 LF 作为换行符,而某些编辑器(如 Windows 上的 Notepad)默认使用 CRLF 作为换行符。为了避免这种警告,你可以在 Git 中设置全局的换行符配置。

解决方法

  1. 打开命令行或终端。
  2. 输入以下命令,将全局的换行符设置为 LF:
bash
git config --global core.autocrlf input
  1. 提交更改:
bash
git add .
git commit -m "Set global line endings to LF"

这样,以后在提交代码时,Git 会自动将 CRLF 转换为 LF,避免出现警告信息。