将 svn 补丁应用到 git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11519230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:13:55  来源:igfitidea点击:

apply svn patch to git repository

gitsvnpatch

提问by victor

Ok, I've tried all answers i could find on stackoverflow, but apparently none seem to be able to solve my problem. I want to apply a patch made by SVN to a git repository. Apparently the easiest way to do it is by using 'git apply', but that does not seem to work.

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

$ 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

This is the content of xxx_parser.patch:

这是 xxx_parser.patch 的内容:

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

now why does it complain that it cannot find file pmd/grammar/JspParser.jjt?

现在为什么它抱怨找不到文件 pmd/grammar/JspParser.jjt?

The path in the patch is pointing to proper directory.

补丁中的路径指向正确的目录。

回答by emcconville

I've had a few issues applying SVN generated patches with git. I'd recommend applying any subversion patches directly with patchcommand, and use git to verify that said patch was successfully applied.

我在使用 git 应用 SVN 生成的补丁时遇到了一些问题。我建议直接使用patch命令应用任何颠覆补丁,并使用 git 验证所述补丁是否已成功应用。

$ patch -p0 < xxx_parser.patch
$ git diff

回答by Vineeth Chitteti

@emcconville answer works if you have patchas an executable command in command line.

如果您patch在命令行中有一个可执行命令,@emcconville 答案会起作用。

For others:

为他人:

  1. Go the svn repo

    svn diff --git >> gitFormat.patch

  2. From your (Copy this file to the) git repo

    git apply gitFormat.patch

  1. 去svn repo

    svn diff --git >> gitFormat.patch

  2. 从您的(将此文件复制到)git repo

    git apply gitFormat.patch