简体   繁体   English

始终无法在远程Linux计算机上应用SVN修补程序

[英]Always fail to apply SVN patch on remote Linux machine

My typical work process is like: 我的典型工作流程如下:

  1. Check out the codes from trunk on to my windows work machine 查看从主干到我的Windows工作机器的代码
  2. Do some fixes (but no commit the SVN) and create a patch of these modifications using Tortoise SVN's "Create Patch". 做一些修复(但没有提交SVN)并使用Tortoise SVN的“创建补丁”创建这些修改的补丁。
  3. SSH log into a remote Linux server, and upload the patch. SSH登录到远程Linux服务器,并上传补丁。 The linux server also has the trunk HEAD checked out. linux服务器还检出了主干HEAD。
  4. Apply the patch on the Linux Server like: 在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.)

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. 我认为这是由于Windows和Linux上的行尾不同的原因造成的,所以我使用dos2unix转换了补丁,警告(如从补丁中删除尾随CR)消失了,但补丁仍然失败。

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 非常感谢

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. 使用cygwin svn diff来避免头痛,将确保每个hunk的头部只有LF作为行结束而不是CR + LF。 The Linux patch command does not play well with hunk headers having CR+LF line endings. Linux patch命令不适用于具有CR + LF行结尾的hunk头。 To me TortoiseSVN/create patch is broken because the patches it creates are not cross-platform. 对我来说TortoiseSVN / create patch是破坏的,因为它创建的补丁不是跨平台的。

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! 我的工作副本有Windows Line Endings(CR + LF),但在我将受影响的文件(在工作副本中)转换为Unix Line Endings后,补丁工作了! 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. 我想,如果Windows可以处理它们,我最终会将整个存储库转换为Unix行结尾。

Hope it helps. 希望能帮助到你。

您可以尝试在修补命令中添加“-l --binary”,如下所示:

    patch -p0 -l --binary < patch.diff

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

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