首页 > 解决方案 > 我想将 svn 项目复制到带有历史记录的 git

问题描述

我想将 svn 项目复制到 linux 环境下的 git 项目。目前我在 svn repo 中有我的项目,其中包含分支、标签和主干文件夹结构。我需要将所有内容复制到 git repo,包括历史记录。我想过使用 svn2git,但对我需要遵循的步骤没有一个好主意。

标签: gitsvngit-svn

解决方案


svn2git 是一个很棒的工具。我正在使用它来迁移一个大型项目。您需要为每个分支/标签定义规则。外卡是你的朋友。

trunk/A/B
branches/Foo/A/B
branches/Bar/A/B
tags/Baz/A/B
tags/Foobar/A/B

以下是一些示例规则。注意:规则按顺序运行。

match /trunk/
  branch master
end match

match /branches/([^/]+)/
  branch \1
end match 

match /tags/([^/]+)/
  branch refs/tags/\1
  annotated true
end match

这将产生以下分支:master、Foo 和 Bar 以及标签 Baz 和 Foobar。

我花了一段时间才弄清楚是否需要更深入地挖掘使用递归函数所需的路径。例如,如果提交将所有分支复制到标签中,则路径将只是 /branches/。你需要规则去一个目录。

match /branches/$
  action recurse
end match

在编写规则之前使用的另一个好工具是 svneverever。它将帮助您编写规则。

https://blog.hartwork.org/posts/before-svn2git-you-want-to-run-svneverever/


推荐阅读