本文由LinuxProbe.Com团队成员魏丽猿整理发布,原文来自:爱开源。

1.物理环境

  Git–server    Centos5.8    192.168.1.245  Svn–server    Centos5.8    192.168.1.108  

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

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

  cat /tmp/userinfo.txt  david=sfzhang  yanni=yanni

3.克隆一个git版本库

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

  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 查看项目提交的历史记录,包括作者,日照,和提交注释信息等。

  cd yanzi  git log  commit 3c4907782804096ea3fa3fb5419dcce610e56f1f  Author: david  Date:   Fri May 10 10:27:50 2013 +0000

5.列出当前所有的分支

  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

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

7.将多余的branches删除掉

  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.再次列出当前的所有分支

  git branch -r    trunk    yanziios1.0.1-build-2223-branch-002

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

  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用户

  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服务器地址

  git remote add origin [email protected]:/data/gitdata/yanziios.git

12.推送全部的分支和标签信息到git服务器上

  git push origin master --tags

之后就是SVN迁移到Git测试,在客户端用SourceTree工具克隆一个Git服务端仓库yanziios.git,在SourceTree图形界面里面可以看到git用户提交的Graph信息,描述信息(Description),日期,作者和版本号等信息。

相关知识链接:https://www.linuxprobe.com/chapter-21/

本文原创地址:https://www.linuxprobe.com/svn-move-to-git.html编辑:逄增宝,审核员:暂无

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。
超哥软件库 » svn 迁移到git