我阅读了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

我不希望它这么简单,也不希望它是一个命令。但我确实希望它不要试图解释任何事情——只是说在这个例子中应该采取什么步骤。


当前回答

我使用了svn2git脚本,工作起来很有魅力。

其他回答

为此,我使用了svn2git库,过程如下:

sudo apt-get安装git-core git-svn-rubysudo gem安装svn2gitsvn 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远程添加原点git push—所有原点git push—标记原点

请参阅git-svn官方手册页。特别是,请查看“基本示例”:

跟踪和贡献整个Subversion管理的项目(完成具有主干、标签和分支):

# Clone a repo (like git clone):
    git svn clone http://svn.foo.org/project -T trunk -b branches -t tags

我已经发布了一个将svn转换为git的分步指南(这里),包括将svn标记转换成git标记,将svn分支转换成git分支。

简短版本:

1) 从特定版本号克隆svn。(修订号必须是要移植的最旧版本)

git svn clone --username=yourSvnUsername -T trunk_subdir -t tags_subdir -b branches_subdir -r aRevisionNumber svn_url gitreponame

2) 获取svn数据。这一步是最耗时的一步。

cd gitreponame
git svn fetch

重复git-svn获取,直到无错误完成

3) 更新主分支

git svn rebase

4) 通过复制引用从svn分支创建本地分支

cp .git/refs/remotes/origin/* .git/refs/heads/

5) 将svn标记转换为git标记

git for-each-ref refs/remotes/origin/tags | sed 's#^.*\([[:xdigit:]]\{40\}\).*refs/remotes/origin/tags/\(.*\)$#\2 \1#g' | while read p; do git tag -m "tag from svn" $p; done

6) 将存储库放在更好的地方,如github

git remotes add newrepo git@github.com:aUser/aProjectName.git
git push newrepo refs/heads/*
git push --tags newrepo

如果你想了解更多细节,请阅读我的帖子或询问我。

魔法:

$ git svn clone http://svn/repo/here/trunk

Git和SVN的操作非常不同。你需要学习Git,如果你想跟踪SVN上游的变化,你需要学习Git-SVN。git-svn主页有一个很好的示例部分:

$ git svn --help

实现这一目标有不同的方法。我尝试了其中的一些,发现在Windows操作系统上只安装了git和svn就可以了。

前提条件:

windows上的git(我用过这个)https://git-scm.com/ 安装了控制台工具的svn(我使用过乌龟svn)转储SVN存储库的文件。svnadmin转储/path/to/repository>repo_name.svn_dump

实现最终目标的步骤(将所有具有历史记录的存储库移动到git,首先是本地git,然后是远程git)

在REPO_NAME_FOLDER目录中创建空存储库(使用控制台工具或tortoiseSVN)cd REPO_NAME_PARENT_FOLDER,将dumpfile.dump放入REPO_NAME_PARENT_FOLDsvnadmin load REPO_NAME_FOLDER<dumpfile.dump等待此操作,可能需要很长时间此命令是无声的,因此打开第二个cmd窗口:svnserve-d-R--root REPO_NAME_FOLDER为什么不直接使用file:///...... ? 因为下一个命令将失败,无法打开。。。到URL:,感谢您的回答https://stackoverflow.com/a/6300968/4953065创建新文件夹SOURCE_GIT_foldercd源_GIT_FOLDERgit-svn克隆svn://localhost/等待此操作。

最后,我们得到了什么?

让我们查看本地存储库:

git log

看到您以前的提交吗?如果是-好

现在,您已经拥有了功能齐全的本地git存储库,其中包含您的源代码和旧svn历史记录。现在,如果要将其移动到某个服务器,请使用以下命令:

git remote add origin https://fullurlpathtoyourrepo/reponame.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

在我的情况下,我不需要标签命令,因为我的repo没有标签。

祝你好运