git提交忽略换行

warning: in the working copy of 'app/Http/Controllers/admin/ProductController.php', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'app/Http/Factorys/Storage/Obs.php', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'composer.json', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'composer.lock', LF will be replaced by CRLF the next time Git touches it

这些警告信息表明你在使用 Git 版本控制系统时,遇到了行结束符(line ending)的问题。在不同的操作系统中,行结束符是不同的:

  • 在 Unix-like 系统中(包括 Linux 和 macOS),行结束符通常是换行符(LF),即 \n
  • 在 Windows 系统中,行结束符是回车和换行的组合(CRLF),即 \r\n

Git 默认使用 LF 作为行结束符,但是当你在 Windows 系统上使用 Git 时,Git 会尝试自动转换行结束符为 CRLF,以适应 Windows 系统。

警告信息中的 LF will be replaced by CRLF the next time Git touches it 表示 Git 将在下一次操作时自动将这些文件中的 LF 转换为 CRLF。

如果你想要避免这种自动转换,或者想要改变 Git 对行结束符的处理方式,你可以设置 Git 的 core.autocrlf 配置选项。以下是一些常用的设置:

  • 设置为 true:在提交时将 LF 转换为 CRLF,检出时再转换回 LF。这适用于在 Windows 上开发,但希望在仓库中保持 LF 的情况。
  • 设置为 false:不进行任何转换,适用于 Unix-like 系统或者你不希望 Git 做任何转换的情况。
  • 设置为 input:仅在提交时将 CRLF 转换为 LF,适用于当你从 Windows 检出代码到 Unix-like 系统时。

你可以通过以下命令来设置 core.autocrlf

git config --global core.autocrlf true

或者

git config --global core.autocrlf false

或者

git config --global core.autocrlf input

选择适合你开发环境的配置。如果你已经设置了这个配置,但仍然看到这些警告,可能需要检查你的 .gitattributes 文件,确保它没有覆盖全局设置。

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一分半心动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值