简体   繁体   English

Git CRLF 和 LF 行在 windows/linux 上结束

[英]Git CRLF and LF line ending on windows/linux

I am working on a project which uses both CRLF and LF line endings.我正在开发一个同时使用 CRLF 和 LF 行尾的项目。 I am working on windows.我正在研究 windows。

  • I created a patch that converts a file from using CRLF line endings to LF line endings.我创建了一个补丁,将文件从使用 CRLF 行结尾转换为 LF 行结尾。
  • I then formatted the patch with git format-patch .然后我用git format-patch When I open this patch, it has correct LF line endings.当我打开这个补丁时,它有正确的 LF 行尾。 The patch says the file is similar at 97% (only the line endings have been changed).补丁说该文件在 97% 处相似(仅更改了行尾)。
  • I sent it to someone using git send-email .我使用git send-email将其发送给某人。 When I observe the mail sent with wireshark, all the line endings have been converted to CRLF.当我观察到用wireshark发送的邮件时,所有的行尾都被转换为CRLF。
  • When someone else receive this patch (working on windows aswell), all the line endings are CRLF in the patch.当其他人收到此补丁时(也在 windows 上工作),补丁中的所有行尾都是 CRLF。
  • The patch can be applied, but the file which should have seen its line endings modified remains the same: no LF line ending conversion.可以应用补丁,但应该看到其行尾被修改的文件保持不变:没有 LF 行尾转换。 When using git show HEAD , the file is said to be similar at 100%, even though the patch being applied said there should be a similarity of 97%.当使用git show HEAD时,据说该文件的相似度为 100%,即使应用的补丁说应该有 97% 的相似度。

How is it possible to send a patch with LD line ending on windows?如何发送以 windows 结尾的 LD 行的补丁? Thanks谢谢

Don't forget to add a .gitattributes rule for that file, in order to force lf for that file不要忘记为该文件添加.gitattributes规则,以便为该文件强制 lf

a_file text=auto eol=lf

But regarding your send-email issue, see " git am/format-patch : control format of line endings ", try and use git send-email --transfer-encoding=base64 , to make sure everything is preserved (including eol)但是关于您的发送电子邮件问题,请参阅“ git am/format-patch : control format of line endings ”,尝试使用git send-email --transfer-encoding=base64 ,以确保一切都被保留(包括 eol)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM