如何将 SVN diff 应用到 Git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/659467/
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
How to apply SVN diff to Git?
提问by Andriy Drozdyuk
I have my projects in 2 repositories. One under SVN and one under Git. Whenever I change something in SVN I want to do the same thing to the Git repository.
我的项目在 2 个存储库中。一种在 SVN 下,一种在 Git 下。每当我在 SVN 中更改某些内容时,我都想对 Git 存储库执行相同的操作。
Say I make a change to SVN repository, producing revision 125. How would I apply these same changes to my Git repository (assuming my Git repository is up to date with revision 124).
假设我对 SVN 存储库进行了更改,生成了修订版 125。我将如何将这些相同的更改应用到我的 Git 存储库(假设我的 Git 存储库是最新的修订版 124)。
Thank you.
谢谢你。
采纳答案by Andriy Drozdyuk
What I actually did/looking for was:
我实际做/寻找的是:
cd /path/to/svn/repo
svn diff -r 125 > /tmp/patch.diff
cd /path/to/git/repo
patch -p0 < /tmp/patch.diff
回答by MattJ
Try:
尝试:
svn diff | patch -d /path/to/git/repo -p0
See svn help diff
if you want to export a specific revision's diff.
查看svn help diff
您是否要导出特定修订的差异。
回答by sehe
Why does no one like git-svn? I cannot assume no-one knows about it.
为什么没有人喜欢 git-svn?我不能假设没有人知道它。
There is git-svn (and git-hg and git-cvs and git-bzr afaict). At least with git-svn you can simply do
有 git-svn(以及 git-hg 和 git-cvs 和 git-bzr afaict)。至少使用 git-svn 你可以简单地做
git svn clone --stdlayout http://myrepo/root here
using -s (--stdlayout
) assumes standard trunk/ branches/ tags/ layout, but you can have it any which way (man git-svn
).
使用 -s ( --stdlayout
) 假定标准主干/分支/标签/布局,但您可以使用任何方式 ( man git-svn
)。
The mapping is bidirectional, so you can push and pull as with a native (git) remote. No questions asked.
映射是双向的,因此您可以像使用本机 (git) 遥控器一样进行推送和拉取。无话可问。
回答by bahrep
If you are going to generate a patch in SVN and apply it with Git later, don't forget to use --git
command-line option:
如果您打算在 SVN 中生成补丁并稍后通过 Git 应用它,请不要忘记使用--git
命令行选项:
--git
Enables a special output mode for svn diff designed for cross-compatibility with the popular Git distributed version control system.
--git
为 svn diff 启用特殊输出模式,旨在与流行的 Git 分布式版本控制系统交叉兼容。
For example, run
例如,运行
svn diff --git -r 125 > /tmp/patch.diff
svn diff --git -r 125 > /tmp/patch.diff
回答by Federico Builes
Besides using patch as mentioned above you could also consider setting up a post-commit hookso you don't have to do this every time you commit something new.
除了使用上面提到的补丁之外,您还可以考虑设置一个提交后挂钩,这样您就不必每次提交新内容时都这样做。
回答by Abhishek Bedi
The below worked for me.
以下对我来说有效。
Source:How to create and apply a patch with Git
First, take a look at what changes are in the patch. You can do this easily with git apply
首先,看看补丁中有哪些变化。您可以使用 git apply 轻松完成此操作
git apply --stat fix_empty_poster.patch
Note that this command DOES NOTapply the patch, but only shows you the stats about what it'll do. After peeking into the patch file with your favorite editor, you can see what the actual changes are.
请注意,此命令不会应用补丁,而只会向您显示有关它将执行的操作的统计信息。使用您喜欢的编辑器查看补丁文件后,您可以看到实际的更改。
Next, you're interested in how troublesome the patch is going to be. Git allows you to test the patch before you actually apply it.
接下来,您对补丁的麻烦程度感兴趣。Git 允许您在实际应用补丁之前对其进行测试。
git apply --check fix_empty_poster.patch
If you don't get any errors, the patch can be applied cleanly. Otherwise you may see what trouble you'll run into.
如果您没有收到任何错误,则可以干净地应用补丁。否则你可能会看到你会遇到什么麻烦。
To apply the patch, I'll use git am instead of git apply. The reason for this is that git am allows you to sign off an applied patch. This may be useful for later reference.
要应用补丁,我将使用 git am 而不是 git apply。这样做的原因是 git am 允许您签署应用的补丁。这可能对以后的参考有用。
git am --signoff < fix_empty_poster.patch
Applying: Added specs to test empty poster URL behaviour
Applying: Added poster URL as part of cli output
Okay, patches were applied cleanly and your master branch has been updated. Of course, run your tests again to make sure nothing got broken.
好的,补丁已应用干净,您的主分支已更新。当然,再次运行您的测试以确保没有任何问题。
In you git log, you'll find that the commit messages contain a “Signed-off-by” tag. This tag will be read by Github and others to provide useful info about how the commit ended up in the code.
在您的 git log 中,您会发现提交消息包含一个“Signed-off-by”标签。这个标签将由 Github 和其他人读取,以提供有关提交如何在代码中结束的有用信息。