将 svn 存储库迁移到 scm-manager 中的 git 存储库

Migrate a svn repository to a git repository in scm-manager

我已经在我的 windows 服务器 2012 r2 上安装了 scm-manager 1.45 作为服务。

我有一个颠覆存储库转储文件。 我设法将其导入到 scm-manager 中的颠覆回购。但我真的很想将其迁移到 git 存储库,但我似乎无法弄清楚如何。我希望所有提交历史都遵循。

在您用来保存共享存储库的工具之外,svn-git 和一点命令行魔法应该可以解决您的问题

我假设迁移是从类 Unix 系统完成的,例如Linux、mac 甚至 cygwin running in a windows machine; You may try use the 'Git Bash' installed with msysgit in windows platforms if you don't have a proper cygwin 安装可用


1#获取SVN仓库贡献者列表

将提交者列表提取到 SVN 存储库,为此,运行(从您的 SVN 存储库的根目录):

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", ); sub(" $", "", ); print " = "" <"">"}' | sort -u > authors-transform.txt

它将创建一个包含作者列表的文件,如:

jsmith = jsmith <jsmith>

您需要将其修改为:

jsmith = John Smith <john.smith@evil_corporation.com>

这一步很重要,因为 git 将在下一步中使用它来将 SVN 提交者 ID 转换为 git 提交者 ID(请注意,如果您需要,您可以手动创建此文件更喜欢)


2# 将 SVN 存储库克隆为 Git 存储库

为此,执行:

git svn clone <SVN_repo_URL> -A authors-transform.txt --stdlayout ~/svn-git-migration

其中:

  • <SVN_repo_URL> 是您的 SVN 存储库,authors-transform.txt 是您刚刚创建的文件。

请注意,如果您使用 "standard" SVN 分支命名法作为您的 SVN 存储库布局,它将正常工作,如果不是这种情况,您需要向 git 指出-svn 通过将 --stdlayout 参数替换为

创建分支的 "folders" 的名称
  • -T(对于 t运行k 路径)

  • -b(分支路径)

  • -t(用于标签路径)参数

(你可能会找到关于git-svn clone命令的详细解释here)

这一步可能需要一段时间(它详细阐述了 SVN 增量的 git 历史),但是当它完成时,您的 SVN 存储库的 git 版本将在您的主目录,在 svn-git-migration 文件夹中(如果您愿意,可以在命令中指定任何其他路径)


3# 将版本库(标签和主分支)结构转换为git

注意:这些命令需要从您的新 git 存储库中执行,因此您需要移至您在上一步中克隆存储库的文件夹

Subversion 处理标签的方式与 git 不同; Git tahs retaled to a single commit (a git tag simply contains a commit ID), SVN tags are an special king of branches, 所以在这里,我们需要定位存储库标签分支(查找进入 refs/heads/tags) 并在所有的尖端应用标签:

git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";
done

此外,我们需要将SVN中的主分支(t运行k重命名为git主分支'master'

git branch -m trunk master

现在只需将 new/migrated git 存储库推送到 git 服务器(scmmanager?)即可完成 :-)。请记住,您需要将 git 服务器存储库添加为远程存储库,here 您可能会在这方面找到一些帮助。

看到您在 SCM 管理器存储库所在的位置具有 read/write 权限。

  1. 创建 SCM 管理器存储库所在的新目录 MyProject;
  2. 进入我的项目;
  3. 执行命令git svn clone theURLfromSCMmanagerSvnRepo;
  4. 通过 SCM-manager 添加新的存储库 "Import repositories" --> 在存储库导入向导中选择 Git --> 从目录导入。
  5. 它现在应该检测到您的新存储库。