[英]Is "git checkout --patch" incompatible with autocrlf=true?
On my windows machine I'm considering setting autocrlf = true
in my .gitconfig.在我的 Windows 机器上,我正在考虑在我的 .gitconfig 中设置
autocrlf = true
。 Others on my team have it set this way and we've ended up with a mix of lf
& crlf
in the repo.我团队中的其他人是这样设置的,我们最终在 repo 中混合了
lf
和crlf
。 I've considered a few options and this seems like the path of least resistance...我已经考虑了一些选择,这似乎是阻力最小的路径......
One thing I've noticed is that git checkout -p
fails with the error patch does not apply
when autocrlf = true
.我注意到的一件事是
git checkout -p
失败,错误patch does not apply
在autocrlf = true
时patch does not apply
。 If I change it back to false
it works as expected.如果我将其改回
false
它将按预期工作。
Is autcrlf = true
incompatible with checkout --patch
or is do I need to set some other option to get it to work? autcrlf = true
是否与checkout --patch
不兼容,还是我需要设置一些其他选项才能使其工作?
Interestingly git add --patch
works as expected with autocrlf = true
.有趣的是
git add --patch
与autocrlf = true
一起按预期工作。
Yes , git checkout --patch
works properly with line ending translation.是的,
git checkout --patch
与行尾翻译正常工作。 The patch almost certainly isn't applying because you have mismatched configuration.该补丁几乎肯定不会应用,因为您的配置不匹配。
Everybody on your team needs to use the same line ending configuration.您团队中的每个人都需要使用相同的行尾配置。
core.autocrlf=true
isn't an option that one person on a team can enable; core.autocrlf=true
不是团队中的一个人可以启用的选项; everybody needs the same settings.每个人都需要相同的设置。 That's because if you have
core.autocrlf=false
, then you're telling Git that the contents on disk are identical to the contents in the repository.那是因为如果您有
core.autocrlf=false
,那么您就是在告诉 Git 磁盘上的内容与存储库中的内容相同。 If you're on Windows, that means that you're checking in files with Windows-style line endings ( \\r\\n
).如果您使用的是 Windows,则意味着您正在签入带有 Windows 样式行结尾 (
\\r\\n
) 的文件。 If you have a colleague who enables core.autocrlf=true
, then you're telling Git that the contents on disk have Windows-style line endings while the contents in the repository have Unix style line endings ( \\n
).如果您的同事启用了
core.autocrlf=true
,那么您就是在告诉 Git,磁盘上的内容具有 Windows 样式的行尾,而存储库中的内容具有 Unix 样式的行尾 ( \\n
)。
But your colleague has told git a lie, since the repository contents actually have \\r\\n
in them.但是您的同事对 git 撒了谎,因为存储库内容实际上包含
\\r\\n
。
A variety of strange things can occur when these settings are mismatched, including things like patches failing to apply.当这些设置不匹配时,可能会发生各种奇怪的事情,包括无法应用补丁之类的事情。
You should instead:你应该:
Set * text=auto
in your .gitattributes
file.在
.gitattributes
文件中设置* text=auto
。 This ensures that everybody working in the repository has the same settings, since the configuration is actually checked in and not something that everybody has to remember to configure properly.这确保在存储库中工作的每个人都具有相同的设置,因为配置实际上是签入的,而不是每个人都必须记住正确配置的内容。
Renormalize the repository, so that the repository contents actually match what you've claimed.重新规范存储库,以便存储库内容实际上与您声明的内容相匹配。 You can do this by
git add --renormalize .
你可以通过
git add --renormalize .
来做到这git add --renormalize .
and checking the contents in.并检查内容。
Once you've done this (and everybody has updated your local working folders), your git apply --patch
should behave correctly.完成此操作后(并且每个人都更新了您的本地工作文件夹),您的
git apply --patch
应该可以正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.