简体   繁体   English

如何将 SVN diff 应用于 Git?

[英]How to apply SVN diff to Git?

I have my projects in 2 repositories.我的项目在 2 个存储库中。 One under SVN and one under Git. SVN 下一个和 Git 下一个。 Whenever I change something in SVN I want to do the same thing to the Git repository.每当我在 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 存储库(假设我的 Z0BCC70105AD279503E31FE7B3F47B614Z 存储库是最新的修订版)。

Thank you.谢谢你。

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

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差异。

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.为 svn diff 启用特殊的 output 模式,旨在与流行的 Git 分布式版本控制系统交叉兼容。

For example, run例如,运行

svn diff --git -r 125 > /tmp/patch.diff

Why does no one like git-svn?为什么没有人喜欢 git-svn? I cannot assume no-one knows about it.我不能假设没有人知道这件事。

There is git-svn (and git-hg and git-cvs and git-bzr afaict).有 git-svn(以及 git-hg 和 git-cvs 和 git-bzr afaict)。 At least with git-svn you can simply do至少使用 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.映射是双向的,因此您可以像使用本机 (git) 远程一样进行推送和拉取。 No questions asked.无话可问。

Besides using patch as mentioned above you could also consider setting up a post-commit hook so you don't have to do this every time you commit something new.除了使用上面提到的补丁之外,您还可以考虑设置一个提交后挂钩,这样您就不必在每次提交新内容时都这样做。

The below worked for me.以下对我有用。

Source: How to create and apply a patch with Git来源: 如何使用 Git 创建和应用补丁

First, take a look at what changes are in the patch .首先,看看补丁有哪些变化 You can do this easily with git apply您可以使用 git 轻松做到这一点

git apply --stat fix_empty_poster.patch

Note that this command DOES NOT apply 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.要应用补丁,我将使用 git am 而不是 git 应用。 The reason for this is that git am allows you to sign off an applied patch.原因是 git am 允许您签署已应用的补丁。 This may be useful for later reference.这可能对以后的参考有用。

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.在您的 git 日志中,您会发现提交消息包含“Signed-off-by”标签。 This tag will be read by Github and others to provide useful info about how the commit ended up in the code. Github 和其他人将读取此标签,以提供有关提交如何在代码中结束的有用信息。

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

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