简体   繁体   English

将 svn repo 与 git repo 合并

[英]Merge svn repo with git repo

I have the daunting task of merging a site with a ton of files between two teams.我有一项艰巨的任务,要在两个团队之间合并一个站点和大量文件。 One team has been working on git and one using svn .一个团队一直在研究git ,一个团队在使用svn Can I please get some help with the best way to go about this?我可以通过最佳方式获得一些帮助吗? What I am thinking is I will create a new bare repo我在想的是我将创建一个新的裸仓库

git clone --bare ~/dir gitversion.git

Then create a branch from there然后从那里创建一个分支

git checkout -b import-svn

Then on that branch I will pull from svn然后在那个分支上我将从 svn 拉

svn checkout svn://svnversion/trunk

Now on this branch I would rebase?现在在这个分支上我会变基吗?

git rebase origin/master

Then switch back to master branch然后切换回master分支

git merge import-svn

I tried something like this but seemed to be getting nowhere.我试过这样的事情,但似乎一无所获。 Never got any merge conflicts or anything which doesnt make sense.从来没有任何合并冲突或任何没有意义的事情。 Can someone please show me a decent workflow to accomplish this?有人可以告诉我一个体面的工作流程来完成这个吗?

I've faced something similar to deal with multiple releases from a SVN-based development.我遇到过类似的事情来处理基于 SVN 的开发的多个版本。 Here is a sketch of how I'd handle it:这是我如何处理它的草图:

# checkout the SVN source
$ svn checkout svn://svnversion/trunk
$ cd /into/svn/checkout

$ git init
$ echo ".svn/" > .gitignore
$ git add .gitignore; git commit -m 'Initial .gitignore'

# Now you have a master branch; create your import-svn branch
$ git checkout -b import-svn

# Add *everything* from the SVN checkout
$ git add -A
$ git commit -m 'Initial SVN'

# Now get the GIT developed stuff
$ git checkout -b import-git master
$ git remote add original-git /path/to/git-developed-repository
$ git pull original-git master         # or whatever branch your git developers used.

# Now you've got two branches 'import-svn' and 'import-git'; DIFF and MERGE as you please

# You don't need the remote anymore.
$ git remote rm original-git

I think that is about right.我认为这是对的。

Now you can think about merging.现在你可以考虑合并了。 Something like the following would work if you considered the 'import-git' as the preferred baseline.如果您将“import-git”视为首选基线,则类似以下内容将起作用。

$ git checkout -b git-merge-svn import-git
$ git diff --name-status import-svn
$ git merge import-svn

You could also try a rebase like follows and then decide which you prefer:您也可以尝试如下变基,然后决定您喜欢哪个:

$ git checkout -b git-rebase-svn import-git
$ git rebase import-svn

And compare the merge and rebase (should be identical, but you never know..)并比较合并和变基(应该是相同的,但你永远不知道..)

$ git diff git-rebase-svn..git-merge-svn

Assuming final repo will be Git.假设最终回购将是 Git。 This solution preserves history on both此解决方案保留了两者的历史记录

First work on a non-bare repositories, it's easier for what you want to do.首先在非裸存储库上工作,你想做的事情更容易。 Clone the git repo, and create another git repo from the SVN one with svn2git .克隆 git repo,并使用svn2git从 SVN 创建另一个 git repo。

So you have two repos.所以你有两个回购。 Add one repo as remote to the other, and import the history into a separate branch :将一个仓库作为远程仓库添加到另一个仓库,并将历史记录导入到一个单独的分支中:

git remote add ../other-repo
git fetch other-repo
git branch other-repo other-repo/master

You will get a warning that there's no base commit, so you'll have two orphan branches您将收到一条警告,指出没有基本提交,因此您将有两个孤立分支

Now you can merge branches.现在您可以合并分支。 This should be terrible, awful, since they are related but completely different history, but then you have no other option.这应该是可怕的,可怕的,因为它们是相关但完全不同的历史,但是你别无选择。 Rebase would be nonsense here since commits are unrelated.由于提交无关,因此 Rebase 在这里是无稽之谈。

There is a recent article on the topic by Microsoft including a walk through using the git-svn utility. 微软最近发表了一篇关于该主题的文章,其中包括使用git-svn实用程序git-svn They provide information on merging with and without svn change history.它们提供有关合并和不合并 svn 更改历史记录的信息。

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

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