有什么方法可以同步 GIT 和 Subversion 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/907913/
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
There is any way to synchronize GIT and Subversion repositories?
提问by Jader Dias
I want to access a repository using both GIT and SVN clients. A way I imagined to do that is through automatic two-way migration: when a user PUSHes into the GIT repository, it is also COMMITed in the SVN repository and vice-versa.
我想使用 GIT 和 SVN 客户端访问存储库。我想象的一种方法是通过自动双向迁移:当用户推送到 GIT 存储库时,它也会在 SVN 存储库中提交,反之亦然。
There is any tool that would help me to do that?
有什么工具可以帮助我做到这一点?
采纳答案by Greg Hewgill
The best way to do this is to use git svn
as a Subversion client. This provides two-way integration between a Subversion repository and a Git repository. Once you have a Git repository, you can push that anywhere else to publish it.
最好的方法是git svn
用作 Subversion 客户端。这提供了 Subversion 存储库和 Git 存储库之间的双向集成。拥有 Git 存储库后,您可以将其推送到其他任何地方以发布它。
I do this regularly, at work there is a Subversion repository that is the "master" repository, and I usually use git svn
to access it. Sometimes if I'm doing things that need more specific Subversion functionality like merging, I'll use the regular svn
client against the repository instead.
我经常这样做,在工作中有一个 Subversion 存储库,它是“主”存储库,我通常git svn
用来访问它。有时,如果我正在做一些需要更具体的 Subversion 功能(例如合并)的事情,我将使用常规svn
客户端来代替存储库。
回答by Dmitry Pavlenko
回答by mrts
Our team had exactly the same problem and after a bit of experimentation we managed to come up with a git-Subversion bridge that synchronizes changes between our team git repository and the corporate Subversion repository. Our git usage is transparent to other Subversion users.
我们的团队遇到了完全相同的问题,经过一些实验,我们设法提出了一个 git-Subversion 桥,可以同步我们团队 git 存储库和公司 Subversion 存储库之间的更改。我们的 git 使用对其他 Subversion 用户是透明的。
The setup is described in more detail at https://github.com/mrts/git-svn-bridge.
该设置在https://github.com/mrts/git-svn-bridge中有更详细的描述。
We have used this setup in production for more than a year.
我们在生产中使用这种设置已经一年多了。
I guess the biggest caveat of the setup is that the git repository tracks only SVN trunk (or another single branch), thus other git branches will be squashed into one commit during merge to trunk. For us this is no problem - we use short-lived task branches and consider them to be lightweight, ephemeral "units of work" that can go to mainline in a single chunk - and the branch history is retained in git.
我想设置的最大警告是 git 存储库仅跟踪 SVN 主干(或另一个单个分支),因此在合并到主干期间其他 git 分支将被压缩为一个提交。对我们来说,这没问题——我们使用短期任务分支,并将它们视为轻量级、短暂的“工作单元”,可以在单个块中进入主线——并且分支历史记录保留在 git 中。
回答by VonC
You might consider svn2gitto easily import svn to git, and then its mirror ruby application git2svn.
More details in this question.
As mentioned in the other answers, 'git svn
' is mandatory, but those ruby modules help you respect the "subversion branches/directory" while not having them as an actual directory in Git.
您可能会考虑使用svn2git轻松将 svn 导入 git,然后将其镜像 ruby 应用程序git2svn。这个问题的
更多细节。
正如其他答案中所提到的,' ' 是强制性的,但是这些 ruby 模块可以帮助您尊重“颠覆分支/目录”,而不是将它们作为 Git 中的实际目录。git svn
回答by iconoclast
You might also want to check out this solution: http://unethicalblogger.com/posts/2008/10/git_back_subversion_mostly_automagically_part_33, which was used to synchronize a repo between git and subversion, with multiple developers using both git and subversion, and a proxy between them to do the synchronization.
您可能还想查看此解决方案:http: //unethicalblogger.com/posts/2008/10/git_back_subversion_mostly_automagically_part_33,它用于在 git 和 subversion 之间同步 repo,多个开发人员同时使用 git 和 subversion,以及一个代理他们之间做同步。
回答by bla
I have a bare-git central repos + SVN-git bridge - a repos with git svn, tracking SVN in branch 'current' and tracking GIT repository in branch 'gitcentral'
我有一个裸 git 中央存储库 + SVN-git 桥——一个带有 git svn 的存储库,在分支“当前”中跟踪 SVN 并在分支“gitcentral”中跟踪 GIT 存储库
Then I use post-update hook in central git repos like that:
然后我在中央 git repos 中使用 post-update 钩子,如下所示:
#!/bin/bash
# Anything inserted into GIT - move it back to SVN
echo
echo '* Pushing data into SVN branch'
cd /home/git/BRIDGE
unset GIT_DIR
# current - svn branch locally and central git branch on project.git repos
# centralgit - unmodified centralgit branch
git fetch /home/git/repositories/project.git/ master:centralgit || (echo "Error while pulling data into bridge repository"; exit 1)
git checkout -b temp centralgit || exit 2
git rebase current || exit 3
git checkout current || exit 4
git reset --hard temp || exit 5
git svn dcommit || exit 6
git branch -D temp || exit 7
echo '* Pushed correctly data into SVN'
exit 0
That's mostly temporal, but works...
这主要是暂时的,但有效......
回答by Daniel Roseman
Surely an easier way to do it would be to have the main repository stay as Subversion, but use git-svn locally?
当然,更简单的方法是将主存储库保留为 Subversion,但在本地使用 git-svn?