在远程Linux机器上应用SVN补丁总是失败
我典型的工作流程是这样的:
- 检查从 trunk 到我的 Windows 工作机器的代码
- 做一些修复(但不提交 SVN)并使用 Tortoise SVN 的“创建补丁”创建这些修改的补丁。
- 通过 SSH 登录远程 Linux 服务器,并上传补丁。 Linux 服务器还签出了 trunk HEAD。
- 在 Linux 服务器上应用补丁,如下所示:
[work@remoteLinuxBox:~/work] patch -p0 -i ~/work/fix.patch (Stripping trailing CRs from patch.) patching file src/java/main/myApp/view/action/test/launch/GetPeekAction.java Hunk #1 FAILED at 385. 1 out of 1 hunk FAILED -- saving rejects to file src/java/main/myApp/view/action/test/launch/GetPeekAction.java.rej (Stripping trailing CRs from patch.) patching file src/java/main/myApp/view/action/test/GetAllCustomerAction.java Hunk #1 FAILED at 76. 1 out of 1 hunk FAILED -- saving rejects to file src/java/main/myApp/view/action/test/GetAllCustomerAction.java.rej (Stripping trailing CRs from patch.)
但我总是遇到这样的错误。我以为是windows和linux上的行尾不同造成的,于是我用dos2unix转换了补丁,类似(Stripping Trailing CRs from patch)的警告消失了,但打补丁仍然失败。
有一种奇怪的行为,如果对文件的修改仅发生在现有行上,则应用补丁将起作用。但如果添加了新行,补丁就会失败。
有人知道如何解决这个问题吗?非常感谢
My typical work process is like:
- Check out the codes from trunk on to my windows work machine
- Do some fixes (but no commit the SVN) and create a patch of these modifications using Tortoise SVN's "Create Patch".
- SSH log into a remote Linux server, and upload the patch. The linux server also has the trunk HEAD checked out.
- Apply the patch on the Linux Server like:
[work@remoteLinuxBox:~/work] patch -p0 -i ~/work/fix.patch (Stripping trailing CRs from patch.) patching file src/java/main/myApp/view/action/test/launch/GetPeekAction.java Hunk #1 FAILED at 385. 1 out of 1 hunk FAILED -- saving rejects to file src/java/main/myApp/view/action/test/launch/GetPeekAction.java.rej (Stripping trailing CRs from patch.) patching file src/java/main/myApp/view/action/test/GetAllCustomerAction.java Hunk #1 FAILED at 76. 1 out of 1 hunk FAILED -- saving rejects to file src/java/main/myApp/view/action/test/GetAllCustomerAction.java.rej (Stripping trailing CRs from patch.)
But I always got errors like these. I thought it was caused by the reason that the end of the line is different on windows and Linux, so I converted the patch using dos2unix, the warning like (Stripping trailing CRs from patch) disappeared, but the patching still failed.
There is one strange behavior that if the modification for a file only happens on a existing line, applying patch will work. But if there are new lines added, the patch gets failed.
Anyone has clue on how to resolve this? Thanks very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 cygwin svn diff 来避免头痛,将确保每个块的标题只有 LF 作为行结尾而不是 CR+LF。
Linux patch 命令不能很好地处理具有 CR+LF 行结尾的大块标头。
对我来说,TortoiseSVN/create patch 已损坏,因为它创建的补丁不是跨平台的。
Use cygwin svn diff to avoid the headache, will make sure that the header of each hunk has only LF as a line ending instead of CR+LF.
The Linux patch command does not play well with hunk headers having CR+LF line endings.
To me TortoiseSVN/create patch is broken because the patches it creates are not cross-platform.
我遇到了类似的问题,我认为不仅补丁文件的行分隔符很重要,而且工作副本的行分隔符也很重要。
我的工作副本有 Windows 行结尾 (CR+LF),但在我将受影响的文件(在工作副本中)转换为 Unix 行结尾后,补丁起作用了!问题是,现在我的文件比较工具显示工作副本文件在每一行中都与存储库不同 - 因为行结尾不同。我想,如果 Windows 可以处理的话,我最终会将整个存储库转换为 Unix 行结尾。
希望有帮助。
I had a similar problem, and I figured that not only the line delimiters of the patch-file are important, but of your working copy as well.
My working copy had Windows Line Endings (CR+LF), but after I converted the affected files (in the working copy) to Unix Line Endings, the patch worked! The problem is, that now my file comparison tool shows that the working copy files are different from the repository in every single line - because of different line endings. I think, I will end up converting the whole repository to Unix line endings, if Windows can deal with them.
Hope it helps.
您可以尝试在修补命令中添加“-l --binary”,如下所示:
You can try to add "-l --binary" to the patching command, like this: