Windows 操作系统使用的 CRLF。
Unix 的操作系统使用的 LF。
Mac OS 起初使用的 CR,后来到了 Mac OS X 后,改成了使用 LF,与 Unix 系统保持一致。
Windows 上 Git 在获取代码时,默认会自动把换行符由 LF 转为 CRLF,在提交时又把 CRLF 转为 LF。
在一些情况下这样会出现问题。
https://git-scm.com/docs/gitattributes
https://github.com/alexkaratarakis/gitattributes
# 提交时转换为 LF,检出时转换为 CRLF git config --global core.autocrlf true # 提交时转换为 LF,检出时不转换 git config --global core.autocrlf input # 提交检出均不转换 git config --global core.autocrlf false # 拒绝提交包含混合换行符的文件 git config --global core.safecrlf true # 允许提交包含混合换行符的文件 git config --global core.safecrlf false # 提交包含混合换行符的文件时给出警告 git config --global core.safecrlf warn # 设置行结束符的类型为 lf git config --global core.eol lf # 设置行结束符的类型为 crlf git config --global core.eol crlf # 设置行结束符的类型为 native, native 是指平台默认的行结束符。默认的类型是 native git config --global core.eol native git config --global core.filemode false
开发仅在 Windows 上运行的项目,可以将 core.autocrlf 设置 false。
sudo apt-get install dos2unix # 当前目录及其子目录下所有文件换行符转由 CRLF 为 LF find ./ -type f -exec dos2unix {} +
https://git-scm.com/book/zh/v2/自定义-Git-配置-Git
原文:https://www.cnblogs.com/jhxxb/p/13237462.html