cxl
Published on 2025-01-09 / 55 Visits
7
0

Git换行符问题

#it

问题:

当提交代码执行 git add 命令时报关于换行符系统兼容性提醒:LF will be replaced by CRLF the next time Git touches it

处理:

Git 有一个配置选项 core.autocrlf,它控制 Git 如何处理换行符:

  • true: 在提交时,将 CRLF 转换为 LF;在检出代码时,将 LF 转换为 CRLF。

  • input: 在提交时,将 CRLF 转换为 LF;检出代码时不转换。

  • false: 提交和检出代码时,不进行任何换行符转换。

git config --global core.autocrlf  # 查看当前配置
git config --global core.autocrlf true   # 设置为true


Comment