gpt4 book ai didi

git - 如何使用 CRLF 强制 git commit?

转载 作者:行者123 更新时间:2023-12-05 04:05:25 26 4
gpt4 key购买 nike

如果我使用autocrlf,它看起来像这里

                     push    clone
1) true: x -> LF -> CRLF
2) input: x -> LF -> LF
3) false: x -> x -> x

但我想要使用 CRLF 进行 git 自动提交:

x -> CRLF (if I use LF, it will commit with CRLF)

我可以吗?

提前致谢!!!

编辑:我认为 git 不支持它,所以我用 crlf 强制将 lf 更改为 crlf .

最佳答案

您至少可以使用 eol directive in a .gitattributes file 确保文件被正确 check out :

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

This setting forces Git to normalize line endings for this file on checkin and convert them to CRLF when the file is checked out.

结合 git config --global core.autocrlf false 将确保您的文件在您的工作树中可用。


I want when I commit file with CRLF or LF, git change it to CRLF.

使用上面的设置,这似乎是不可能的,因为默认规范化总是在 checkin 时转换 LF。
这只是为了确保您的文件使用正确的 eol(行尾) checkout 。

但是如果你想强制 crlf checkin ,你将需要手动执行。
尝试:

git config --global core.autocrlf false

确保在任何 .gitattributes 文件中没有任何 core.eoltext eol 指令(以避免任何“重新规范化”)

然后做一个unix2dos在任何用错误的 eol checkout 的文件上。

最后,添加并提交:那些带有 CRLF 的文件仍应使用 CRLF checkin 。

关于git - 如何使用 CRLF 强制 git commit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51229226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com