Lework Study hard, improve every day.

SVN项目迁移到Git

2016-07-09
git
 
本文 2286 字,阅读全文约需 7 分钟

本次服务器的系统版本是:

CentOS release 6.7 (Final)

No.1 环境

ntpdate time.nist.gov
yum -y install install git-core git-svn curl-devel

No.2 需要迁移的svn目录结构

autotest/
└── autotest
    ├── docs
    ├── files
    ├── src
    └── webapp

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

svn log --quiet svn://192.168.1.202:9999/autotest | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq | while read line;do echo "$line = $line <$line@test.com>"; done >> authors.txt
cat authors.txt 
    user1 = user1 <user1@test.com>
    user2 = user2 <user2@test.com>

No.4 通过git svn clone克隆一个git版本库

git svn clone svn://192.168.1.202:9999/autotest  --authors-file=authors.txt

No.5 添加svn忽略

cd autotest/
git svn show-ignore > .git/info/exclude
cat .git/info/exclude 

/autotest/aoslogs
/autotest/build
/autotest/webapp/WEB-INF/classe

No.6 通过git log命令查看提交日志

[root@master autotest]# git log 
commit 9db475c1d6bf7c19f3bcd116f9669c417650d4fc
Author: user1 <user1@test.com>
Date:   Wed Jul 13 02:18:18 2016 +0000

    更新文档、代码格式
    
    git-svn-id: svn://192.168.1.202:9999/autotest@30 dbc118c4-3914-11e6-a1d3-095300b87b17
...

No.7 建立gitlab项目,并添加远程git服务器地址

git remote add origin http://username@192.168.1.20/username/autotest.git

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

git push --all origin
git push --tags origin

No.7 svn帐号密码迁移到gitlab上

cat passwd.conf | while read line; do passwd=`echo $line | cut -d " " -f3`; user=`echo $line | cut -d " " -f1`;curl -d "password=$passwd&email=$user@test.com&username=$user&name=$user" --header "PRIVATE-TOKEN: yNxg9eVxkzXy1hVd8Ls2"  "http://192.168.77.132/api/v3/users"; done

passwd.conf 是svn密码文件

PRIVATE-TOKEN 是gitlab的管理员用户的api 访问密钥


push的时候遇到错误

  1. The requested URL returned error: 401 Unauthorized while accessing.

    解决方法: 更新git客户端

  2. fatal: Unable to find remote helper for ‘http’

    解决方法:

export PATH=$PATH:/usr/libexec/git-core

git svn clone 参数说明

git svn clone http://svn.example.com/project --trunk trunk --branches branches --tags tags project
  • –no-metadata 表示阻止git导出SVN包含的一些无用信息
  • –authors-file 表示SVN账号映射到git账号文件,所有svn作者都要做映射
  • –trunk 表示主开发项目
  • –branches 表示分支项目
  • –tags 表示标签项目
  • –ignore-refs 表示不包含后面的分支项目
  • -s 表示告诉 Git 该 Subversion 仓库遵循了基本的分支和标签命名法则 即-T trunk -b branches -t tags
  • project 表示git项目名称

例子

svn 目录

├── branches
│   ├── 1.4.1
│   ├── 2.1.0
│   ├── 2.2.8
│   └── 3.0.3
├── tags
└── trunk

对应着git svn clone命令

git svn clone -s http://test.com/svn/
原文地址 https://lework.github.io/2016/07/09/svn_to_git/

上一篇 安装git

下一篇 更新git

Comments

Content