如何在 Linux 中使用在 Windows 中创建的补丁(带 CRLF)?
仅针对 unix 文本文件硬编码的标准 linux 补丁。
PS:我不想将所有内容转换为unix,然后将结果转换回来。
Standard linux patch hard-coded only for unix text files.
PS: I do no want convert ALL to unix and then convert result back.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我以前遇到过这个问题几次。这是我发现的:
这就是我所做的:
如果您想保留该约定,可以使用 unix2dos 将修补文件转换回 CRLF 行结尾。
I've run into this problem before a few times. This is what I've discovered:
So this is what I did:
You can use unix2dos to convert patched files back to CRLF line-endings if you want to maintain that convention.
使用 --binary 选项。以下是手册页中的相关片段:
Use the --binary option. Here is the relevant snippet from the man page:
组合:
最后一行取决于您是否要保留 CRLF。
M.PS。
这应该是对 cscrimge 帖子的回复。 DS。
Combined:
The last line depends on whether you want to keep the CRLFs or not.
M.
PS. This should've been a reply to cscrimge's post. DS.
这是我们办公室的一个人提出的解决方案,所以我不会因此而获得荣誉,但它在这里对我有用。
有时我们会遇到在同一个文件中混合linux和windows行结尾的情况,并且我们还从windows创建补丁文件并将其应用到linux上。
如果您在 Windows 上创建补丁文件后遇到补丁问题或者您有混合行结尾,请执行以下操作:
dos2unix 补丁文件
dos2unix $(sed -n 's/^Index: //p' 补丁文件)
patch -p0 -i 补丁文件
This is a solution one of our guys came up with in our office, so I'm not taking credit for it but it works for me here.
We have a situation of mixed linux and windows line endings in the same file sometimes, and we also create patch files from windows and apply them on linux.
If you are experience a patch problem after creating your patch file on windows or you have mixed line endings then do this:
dos2unix patch-file
dos2unix $(sed -n 's/^Index: //p' patch-file)
patch -p0 -i patch-file
perl -i.bak -pe's/\R/\n/g' inputfile
将任何行结尾转换为标准。perl -i.bak -pe's/\R/\n/g' inputfile
to convert any line ending to the standard.