如何将带有历史记录的SVN存储库迁移到新的Git存储库?

1619

我读了Git手册、常见问题解答、Git-SVN快速入门等等,它们都解释了这个和那个,但是没有任何地方可以找到像这样简单的说明:

SVN存储库位于:svn:// myserver / path / to / svn / repos

Git存储库位于:git:// myserver / path / to / git / repos

git-do-the-magic-svn-import-with-history \
svn://myserver/path/to/svn/repos \
git://myserver/path/to/git/repos

我不认为这会那么简单,也不指望这是一条命令就搞定。但我期望它不要去解释任何事情——只需要说明根据这个示例应该采取哪些步骤。


10
越来越简单了,我刚刚自己完成了这个过程,并在 Stack Overflow 的帮助下记录了我的发现。http://jmoses.co/2014/03/21/moving-from-svn-to-git.html - John Moses
使用下面的Casey答案,但在运行“svn clone ...”命令之前,请查看如何将额外的“Visual SVN Server”行添加到您的user.txt文件中...在这里:https://dev59.com/_V_Va4cB1Zd3GeqPUpSS - Entree
2
此外,如果您在GitHub个人资料中勾选了“使电子邮件保密”选项,请使用yourgituser@users.noreply.github.com作为users.txt中的电子邮件地址进行匹配,以避免您的真实电子邮件地址出现在提交记录中。 - Entree
要从Google Code迁移,请阅读:如何恢复Google Code SVN项目并迁移到Github - kenorb
34个回答

0

有效地使用Git和Subversion是一个关于git-svn的简单介绍。对于现有的SVN存储库,git-svn使得这个过程非常容易。如果你要开始一个新的存储库,首先创建一个空的SVN存储库,然后使用git-svn导入比相反的方向更加容易。创建一个新的Git存储库,然后导入到SVN中可以完成,但是这有点痛苦,特别是如果你是Git的新手,并希望保留提交历史记录。


0

下载适用于Windows的Ruby安装程序并使用最新版本进行安装。将Ruby可执行文件添加到您的路径中。

  • 安装svn2git
  • 开始菜单 -> 所有程序 -> Ruby -> 使用Ruby启动命令提示符
  • 然后输入“gem install svn2git”并按Enter键

    迁移Subversion存储库

  • 打开Ruby命令提示符并转到要迁移文件的目录

    然后svn2git http://[domain name]/svn/ [repository root]

  • 根据项目代码大小,迁移项目到Git可能需要几个小时。

  • 这个重要的步骤有助于创建如下所述的Git存储库结构。

    SVN (/Project_components) trunk --> Git master SVN (/Project_components) branches --> Git branches SVN (/Project_components) tags --> Git tags

创建远程存储库并推送更改。


0
我使用了以下脚本来读取一个包含所有我的SVN仓库列表的文本文件,并将它们转换为Git,然后使用git clone --bare命令将其转换为裸Git仓库:
#!/bin/bash
file="list.txt"
while IFS= read -r repo_name
do
 printf '%s\n' "$repo_name"
 sudo git svn clone --shared --preserve-empty-dirs --authors-file=users.txt file:///programs/svn/$repo_name
 sudo git clone --bare /programs/git/$repo_name $repo_name.git
 sudo chown -R www-data:www-data $repo_name.git
 sudo rm -rf $repo_name
done <"$file"

list.txt 的格式如下:

repo1_name
repo2_name

users.txt 的格式如下:

(无作者) = Prince Rogers <prince.rogers.nelson@payesley.park.org>

www-data 是 Apache Web 服务器用户,需要权限才能通过 HTTP 推送更改。


-1

为此,我使用了svn2git库,并按照以下步骤进行:

sudo apt-get install git-core git-svn ruby
sudo gem install svn2git
svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq > authors.txt (此命令用于映射作者)

上述步骤应在要从svn转换为git的文件夹中执行。

在authors.txt中每行添加一个映射,如下所示

anand = Anand Tripathi <email_id>
trip = Tripathi Anand <email_id>

创建一个新的Git仓库文件夹,并在其中执行以下命令,其中包含authors.txt文件的路径。
svn2git <svn_repo_path> --nobranches --notags --notrunk --no-minimize-url --username <user_name> --verbose  --authors <author.txt_path>

If no trunk and no tag and branch is present then have to execute the above command else if root is trunk then mention rootistrunk or trunk is present then --trunk <trunk_name>

git remote add origin
git push --all origin
git push --tags origin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接