SVN 到 Git 迁移

SVN to Git migration(SVN 到 Git 迁移)

本文介绍了SVN 到 Git 迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过下载 svn2git.sh 脚本文件并使用以下命令从 SVN 迁移到 Windows 上的 git.

I am trying to migrate from SVN to git on windows by downloading the svn2git.sh script file and using the following command.

sh svn2git.sh [ProjectName] [SVN Repo link] [SVN Rev (Probably 0)] [Stash Repo Link]

我是新手,对 git-svn 和 svn2git 的用法很困惑.谁能建议我使用 svn2git 工具进行 svn 到 git 迁移的步骤?

I am new to this and very confused between git-svn and svn2git usage. Can anyone suggest me the steps for svn to git migration using svn2git tool?

推荐答案

我创建了一个 svn 到 git 迁移的脚本.该脚本将 svn 存储库连同它的所有标签和维护的历史迁移到 git.

I created a script for svn to git migration. This script migrates the svn repo to git along with all it's tags and history maintained.

先决条件:在继续迁移之前,请确保您的计算机上安装了 GIT 和 SVN.

Pre-requisites : Make sure GIT and SVN are installed on your machine before moving ahead with the migration.

使用的变量说明

SVN_REPO_LINK : http 链接到您托管 svn 存储库的位置

SVN_REPO_LINK : http link to where you svn repo is hosted

GIT_REPO_NAME : 你想给你的新 git repo 的名字

GIT_REPO_NAME : the name that you want to give to you new git repo

GIT_REPO_LINK :链​​接到您要在其中托管 repo 的 git 服务器.[它基本上是一个你想要添加的 GIT 遥控器]

GIT_REPO_LINK : link to your git server where you want to host the repo. [It is basically a GIT remote that you would want to add]

作者文件:在 svn 中,提交仅与用户名相关联,但在 git 存储库中,除了用户名之外,还需要电子邮件地址.为了在 git 中维护 svn 提交,需要用户电子邮件.该文件用于此目的.文件格式如下:

Authors File : In svn the commits are associated with the username only, but in git repository email address is also required besides the username. Inorder to maintain the svn commits in git, user emails are are needed. This file serves that purpose. The format of the file is as follows :

svn user name = Name <email>

Helen_david = Helen David <helen.david@mycompany.com>

RobinR = Robin Rose <robin.rose@mycompany.com>

脚本

git svn clone --stdlayout --prefix 'svn/' -A authors.txt $SVN_REPO_LINK $GIT_REPO_NAME
cd $GIT_REPO_NAME

git for-each-ref refs/remotes/svn --format="%(refname:short)" | sed 's#svn/##' | grep -v '^tags'| while read aBranch; do git branch $aBranch svn/$aBranch; done
git branch -d trunk 
git for-each-ref refs/remotes/svn/tags --format="%(refname:short)" | sed 's#svn/tags/##' | while read aTag; do git tag $aTag svn/tags/$aTag; done
git remote add origin $GIT_REPO_LINK
git push -u --all origin
git push --tags origin

现在您的存储库连同它的所有标签、分支和历史记录一起迁移.

Now your repository is migrated along with all it's tags,branches and history.

这篇关于SVN 到 Git 迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:SVN 到 Git 迁移

基础教程推荐