2012-07-17 75 views
32

好吧,我已经尝试了所有可以在stackoverflow上找到的答案,但显然没有人能够解决我的问题。我想将由SVN制作的补丁应用到git存储库。显然,最简单的方法是使用'git apply',但这似乎不起作用。将svn补丁应用到git存储库

$ git apply --ignore-space-change --ignore-whitespace < xxx_parser.patch 


<stdin>:10: trailing whitespace. 
     FORCE_LA_CHECK = false; stdin:23: trailing whitespace. 

<stdin>:79: trailing whitespace 
. 
. 
. 
. 
error: pmd/grammar/JspParser.jjt: No such file or directory 
error: patch failed: pmd/pom.xml:251 
error: pmd/pom.xml: patch does not apply 

这是xxx_parser.patch的内容:

$ head xxx_parser.patch Index: etc/grammar/JspParser.jjt 
--- etc/grammar/JspParser.jjt (revision 7704) 
+++ etc/grammar/JspParser.jjt (working copy) 

现在为什么它抱怨说,它无法找到文件PMD /语法/ JspParser.jjt?

修补程序中的路径指向正确的目录。

+0

您知道补丁文件可以对多个文件进行更改吗?只需查看文件头就可以看到补丁中的第一个文件。 – asm 2012-07-17 11:41:17

回答

43

我有一些问题应用SVN生成的补丁与Git。我建议直接使用patch命令应用任何Subversion修补程序,并使用git来验证所述修补程序是否已成功应用。如果你有patch在命令行可执行命令

$ patch -p0 < xxx_parser.patch 
$ git diff 
+0

不幸的是,当我尝试上述命令断言失败时,出现以下错误:(s &&大小),函数savebuf,文件/SourceCache/gpatch/gpatch-2/patch/util.c,第424行。 中止陷阱:6 – 2012-11-22 10:11:58

+0

我相信在[patch](http://savannah.gnu.org/projects/patch/)的旧版本中,'assert(s && size)'是与“_ \在file_结尾没有换行符”相关的错误。幸运的是,它已经得到解决。确保您的系统是[patch-2.7.1](http://ftp.gnu.org/gnu/patch/)的最新版本。 – emcconville 2012-11-23 14:21:43

+0

如果出现行结束问题(修改了太多行),请尝试使用二进制选项:patch --binary --no-backup-if-mismatch -p0 too 2015-09-07 08:51:29

5

@emcconville答案的作品。

对于其他人:

  1. 去了svn回购

    SVN差异--git >> gitFormat.patch

  2. 从您的(这个文件复制到)混帐回购协议

    git apply gitFormat.patch