SVN数据迁移到Git笔记

由于Git分布式体系结构,用户完全可以脱离Git服务端在本地查看,编辑和提交代码,现在公司Leader要求将SVN上面的数据迁移到Git上面,通过git svn命令可以将SVN里面的数据迁移到Git上面。
1.物理环境
Git-server Centos5.8 192.168.1.245
Svn-server Centos5.8 192.168.1.108

2.建立SVN用户到git用户的映射文件,文件格式如下:

1
2
3
cat /tmp/userinfo .txt
david=sfzhang<shifeng_zhang88@163.com>
yanni=yanni<yanni_liu88@163.com>

3.通过git svn clone克隆一个git版本库,SVN里面包含trunk,branches和tags。

1
git svn clone svn: //192 .168.1.108:9999 /yanzi/ --no-metadata --authors- file =userinfo.txt --trunk=trunkmobile --tags=tags --branches=branches --ignore-refs=refs /remotes/yanzi- .*  yanzi

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

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

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

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

参数yanzi表示git项目名称

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

1
2
3
4
5
cd yanzi
git log
commit 3c4907782804096ea3fa3fb5419dcce610e56f1f
Author: david <shifeng_zhang88@163.com>
Date:   Fri May 10 10:27:50 2013 +0000

5.在git版本库里面tag都是branches(分支),首先列出当前所有的分支。

1
2
3
4
5
6
cd yanzi
git branch -r
   tags /mobile_1 .0.0
   tags /mobile_1 .0.1
   trunk
   yanziios1.0.1-build-2223-branch-002

6.手动将branches分支转换为tags。

1
2
git tag mobile_1.0.0 tags /mobile_1 .0.0
git tag mobile_1.0.1 tags /mobile_1 .0.1

7.将多余的branches删除掉。

1
2
3
4
git branch -r -d tags /mobile_1 .0.0
Deleted remote branch tags /mobile_1 .0.0 (was d50002b).
git branch -r -d tags /mobile_1 .0.1
Deleted remote branch tags /mobile_1 .0.1 (was e7b78a2).

8.再次列出当前的所有分支。

1
2
3
git branch -r
   trunk
   yanziios1.0.1-build-2223-branch-002

9.建立git仓库并初始化版本库。

1
2
3
4
mkdir -p /data/gitdata/yanziios .git
cd /data/gitdata/yanziios .git/
git init --bare
Initialized empty Git repository in /data/gitdata/yanziios .git/

10.将yanziios.git的属主修改为git用户。

1
2
3
4
5
6
7
8
9
10
11
chown git yanziios.git -R
ls -l yanziios.git/
total 64
drwxr-xr-x 2 git root 4096 May 22 12:25 branches
-rw-r--r-- 1 git root   66 May 22 12:25 config
-rw-r--r-- 1 git root   73 May 22 12:25 description
-rw-r--r-- 1 git root   23 May 22 12:25 HEAD
drwxr-xr-x 2 git root 4096 May 22 12:25 hooks
drwxr-xr-x 2 git root 4096 May 22 12:25 info
drwxr-xr-x 4 git root 4096 May 22 12:25 objects
drwxr-xr-x 4 git root 4096 May 22 12:25 refs

11.添加远程git服务器地址。

1
git remote add origin git@192.168.1.245: /data/gitdata/yanziios .git

12.用git push命令推送全部的分支和标签信息到git服务器上面。

1
2
git push origin --tags
git push orign --all

13.SVN迁移到Git测试,在客户端用SourceTree工具克隆一个Git服务端仓库yanziios.git

135104821.jpg

14.在SourceTree图形界面里面可以看到git用户提交的Graph信息,描述信息(Description),日期,作者和版本号等信息。133345317.jpg


总结:

1)在运行git svn clone svn: 命令时出现下面的错误:Can't locate SVN/Core.pm in @INC (@INC contains: /usr/local/git/lib/perl5/site_perl/5.8.需要安装subversion-perl软件包。

2)在运行git pull git@192.168.1.245:/data/gitdata/yanziios.git时出现下面错误:Can't locate Term/ReadKey.pm in @INC (@INC contains:需要运行下面命令:
Pull up the CPAN teminal:
perl -MCPAN -e shell
Once at the cpan prompt install the needed module:
cpan> install Term::ReadKey

3)需要在本机用ssh-keygen -t rsa -C your_email_name生成KEY认证文件,然后把公钥id_rsa.pub追加到git服务器的git用户家目录authorized_keys文件里面。

4)SVN 只有trunk,branches,没有tags导出方法。

git svn clone svn://192.168.1.10:8888/svnproject/ --no-metadata --authors-file=userinfo.txt --trunk=trunk --branches=branches
--ignore-refs=refs/remotes/yanziios1.* gitproject

5)git clone 远程分支git clone git@192.168.1.222:/data/gitdata/yanzi/test.git --branch test-build-1442-branch-001 test-001

6)更多的错误详见http://blog.csdn.net/jingwenlai_scut/article/details/4771348


原文链接: http://sfzhang88.blog.51cto.com/4995876/1198867


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值