我正在寻找一种永久(即导入后不会使用 git-svn 并且将再次克隆存储库以消除所有 git-svn 剩余部分)将我的 SVN 存储库迁移到 git 的方法。通常这将是一件简单的事情 - 只需执行 http://www.jonmaddox.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/。
然而,在 SVN 存储库中,我在一段时间后切换到 trunk/branches/tags 结构,因此约 2000 次提交中大约有一半是在 / 中使用实际的 trunk,而另一半则在 /trunk/ 中(即有一次重大提交移动了所有内容),因此在执行 git svn 初始化时使用 -s
或不使用它都不会正常工作。
我现在正在寻找一种将存储库正确导入 git 的方法,即保留分支信息(没有标签,我从未创建过任何标签),同时不弄乱旧的提交。如果这是不可能的,我想知道是否有一种方法可以重写旧的提交来更改存储库,以便它使用 trunk/branches/tags 结构 - 那么我可以简单地使用 -s
git-svn。
I'm looking for a way to permanently (i.e. no git-svn will be used after the import and the repo will be cloned again to get rid of all git-svn remainders) migrate one of my SVN repositories to git. Usually this would be an easy thing - just doing the steps explained at http://www.jonmaddox.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/.
However, in the SVN repository I switched to the trunk/branches/tags structure after some time, so about half of the ~2000 commits are working with the actual trunk being in / while the other half have it in /trunk/ (i.e. there's one big commit moving everything) so neither using -s
nor not using it when performing the git svn initialization will work properly.
I'm now looking for a way to import the repository to git properly, i.e. preserving the branch information (no tags, I never created any) while not messing up old commits. In case that's not possible I'd like to know if there's a way to rewrite the old commits to change the repo so it uses the trunk/branches/tags structure - then I could simply use -s
in git-svn.
发布评论
评论(1)
TL,DR:当一些手动工作是可以接受的时候,修复像问题中描述的那样混乱的存储库是可能的。最简单的方法是使用 SVN 转储文件,然后使用 git-svn 和 stdlayout 选项简单地导入它。
我设法通过重写存储库的 svndump 以从一开始就包含正确的结构来做到这一点:
然后我使用一个小的内联 Perl 脚本来更改文件夹:
由于转储现在无效 -
trunk
需要在 r0 中创建文件夹,并且需要删除将所有内容从/
移动到/trunk
的提交 - 我手动编辑了转储文件(幸运的是,所有元数据都是纯文本)并且在开头添加以下内容r0 的更改:在提交移动所有文件时,我删除了所有操作并添加了以下内容来创建
branches
文件夹(如果我使用过,则同样对于tags
文件夹)它)现在可以使用 svnadmin load 加载编辑后的转储文件,为我提供了一个可以通过 git-svn 导入而没有任何问题的存储库。
TL,DR: It is possible to fix a messy up repository like the one described in the question when some manual work is acceptable. The easiest way is doing it with the SVN dump file and then simply importing it using git-svn with the stdlayout option.
I managed to do it by rewriting the svndump of the repository to include the proper structure from the beginning:
Then I used a small inline Perl script to change the folders:
Since the dump was now invalid - the
trunk
folder needed to be created in r0 and the commit moving everything from/
to/trunk
needed to be obliterated - I edited the dump file manually (luckily all metadata are plaintext) and added the following at the beginning of the changes for r0:In the commit moving all the files I removed all actions and added the following to create the
branches
folder (likewise for thetags
folder if I had used it)The edited dumpfile could now be loaded using
svnadmin load
, giving me a repository that could be imported by git-svn without any issues.