使用git-svn迁移SVN至GitLab

使用git-svn迁移SVN至GitLab

1、安装gitgit-svn

后面的步骤中对git版本有一定要求,通过yum安装的git版本较低,这里进行编译安装

[root@DevTest ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y

[root@DevTest ~]# wget -c https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz

[root@DevTest ~]# tar xf git-2.9.5.tar.gz

[root@DevTest ~]# cd git-2.9.5

[root@DevTest git-2.9.5]# ./configure --prefix=/usr/local/git

出现报错

解决方法为

[root@DevTest git-2.9.5]# yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker -y

[root@DevTest git-2.9.5]# ./configure --prefix=/usr/local/git        #再次编译

[root@DevTest git-2.9.5]# make && make install

将编译好的gitbin目录添加到bashrc中,相当于添加全局变量

[root@DevTest git]# vim /etc/profile

export GIT_HOME=/usr/local/git

export PATH=$GIT_HOME/bin:$PATH

[root@DevTest git]# git --version

git version 2.9.5

[root@DevTest git]# yum install git-svn -y #安装git-svn

 

2、建立SVN用户到git用户的映射文件

(可选)准备作者文件,以便将SVN作者映射到Git作者。如果您选择不创建authors文件,那么提交将不会归因于正确的GitLab用户。有些用户可能不认为这是一个大问题,而其他用户则希望确保他们完成此步骤。如果您选择映射作者,则需要映射SVN存储库中更改中存在的每个作者。如果不这样做,转换将失败,必须相应地更新作者文件。以下命令将搜索存储库并输出作者列表。

[root@DevTest ~]# svn log svn://192.168.1.20/hyhy --quiet | grep -E "r[0-9]+ | .+ |" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq >/svnauthor/authors.txt

使用最后一条命令的输出来构建作者文件。创建一个名为的文件,authors.txt并为每行添加一个映射

vim /svnauthor/authors.txt

janedoe = Jane Doe <janedoe@example.com>

johndoe = John Doe <johndoe@example.com>

alexdoe = Alex Doe <alexdoe@example.com>

 

3、通过git svn clone克隆一个git版本库,SVN里面包含trunk,branchestags

[root@DevTest ~]# mkdir /data

[root@DevTest ~]# cd /data

[root@DevTest data]# git svn clone svn://192.168.1.20/hyhy --no-metadata --authors-file /svnauthor/authors.txt hyhy

可选参数及含义

参数--no-metadata表示阻止git导出SVN包含的一些无用信息

参数--authors-file表示SVN账号映射到git账号文件,所有svn作者都要做映射

参数--trunkmobile表示主开发项目

参数--branches表示分支项目,--ignore-refs表示不包含后面的分支项目

参数hyhy表示git项目名称

 

4、通过git log 查看项目提交的历史记录,包括作者,日照,和提交注释信息等

[root@DevTest data]# cd hyhy

[root@DevTest hyhy]# git log

 

5、提交代码到gitlab仓库

[root@DevTest hyhy]# rm -rf .git/

[root@DevTest hyhy]# git init    #初始化仓库(创建一个名为 .git 的子目录,这个子目录含有你初始化的 Git 仓库中所有的必须文件,这些文件是 Git 仓库的骨干)

[root@DevTest hyhy]# git remote add origin git@git.xxx.cn:java/hyhy.git    #添加远程项目地址(可从项目主页复制)

[root@DevTest hyhy]# git add . #将修改保存到索引区

[root@DevTest hyhy]# git commit -m "commit code"    #提交所有代码到本地版本库

[root@DevTest hyhy]# git push --all origin    #将本地的更改提交到远程服务器

[root@DevTest hyhy]# git push origin –tags    #推送标签

原文地址:https://www.cnblogs.com/ssgeek/p/9830326.html