git commit时报错,LF will be replaced by CRLF the next time Git touches it

problem

本地执行git commit时,会出现很多文件出现diff信息,实际文件并没有修改,通过 git diff,
出现提示是 warning: in the working copy of ‘vite.config.ts’, LF will be replaced by CRLF the next time Git touches it。是什么原因导致的?怎么解决?

reason

出现这种情况的原因是你的 Git 配置或操作系统的行尾字符设置不同。
通常在 Unix/Linux 和 macOS 上,行尾字符是 LF (Line Feed, \n),
而在 Windows 上,行尾字符是 CRLF (Carriage Return and Line Feed, \r\n)。
简单来说,windows是\r\n,mac是\n导致

solution

Visual Studio Code 如何查看换行符类型?
在 VS Code 窗口的右下角,有一个显示当前文件换行符类型的区域。它通常会显示为 CRLF 或 LF。
CRLF 表示文件使用的是 \r\n 作为换行符(Windows 风格)。
LF 表示文件使用的是 \n 作为换行符(Unix/Linux 和 macOS 风格)

解决办法:

  1. windows环境
    git config --global core.autocrlf true
    在检出文件时将行尾字符转换为 CRLF,而在提交时将其转换回 LF
    实际测试:没有用

  2. 配置prettier的配置文件,忽略行尾字符
    .prettierrc 新增 “endOfLine”: “auto”

相关推荐

  1. 【MySQL】创建用户时报

    2024-07-18 05:42:04       50 阅读
  2. docker commit镜像时报

    2024-07-18 05:42:04       32 阅读
  3. Vue中使用Element-ui时报

    2024-07-18 05:42:04       41 阅读
  4. Nodejs引入模块运行时报

    2024-07-18 05:42:04       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 05:42:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 05:42:04       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 05:42:04       58 阅读
  4. Python语言-面向对象

    2024-07-18 05:42:04       69 阅读

热门阅读

  1. 数据库管理-第221期 Oracle的高可用-04(20240717)

    2024-07-18 05:42:04       21 阅读
  2. 构建自动化:在Gradle中配置项目变量

    2024-07-18 05:42:04       22 阅读
  3. PL/SQL oracle上多表关联的一些记录

    2024-07-18 05:42:04       23 阅读
  4. vb6读取mysql,用odbc mysql 5.3版本驱动

    2024-07-18 05:42:04       19 阅读
  5. 在Spring Boot 中使用Kafka

    2024-07-18 05:42:04       23 阅读
  6. 响应式编程:Project Reactor与WebFlux

    2024-07-18 05:42:04       20 阅读
  7. Django+vue自动化测试平台(28)-- ADB获取设备信息

    2024-07-18 05:42:04       23 阅读
  8. 2024牛客暑期多校训练营1 I.Mirror Maze(题解)

    2024-07-18 05:42:04       21 阅读
  9. 浅谈Git

    浅谈Git

    2024-07-18 05:42:04      21 阅读
  10. 力扣649.Dota2参议院

    2024-07-18 05:42:04       25 阅读