SVN迁移GIT简单方式(实践可用)
1. 安装GIT
- sudo yum install git
安装的是默认的版本,如果要安装指定版本要使用安装包,这种方式简单,正常也能使用。
2. 安装迁移工具git-svn
-
sudo yum install git-svn
同样yum安装
3. 获取svn用户
-
可以使用命令
svn log ^/ --xml | grep -P "^<author" | sort -u | perl -pe 's/<author>(.*?)<\/author>/$1 = $1 <$1\@email.com>/' >> ../users.txt
- 或者使用工具svn-migration-scripts.jar
下载地址https://bitbucket.org/atlassian/svn-migration-scripts/downloads
执行命令,如果svn需要登陆,在URL上加https://user:pwd@svn.example.com,推荐这种方式
java -jar svn-migration-scripts.jar authors https://svn.example.com > authors.txt
4.执行迁移
-
sudo git svn clone http://user:pwd@example/svn/code --username=user --no-metadata --authors-file=authors.txt myGit & >/dev/null
命令中还可以带branch,tag等分支参数,详细可以看其他资料,这里SVN URL直接取到主分支。authors-file用步骤3生成的文件,这个文件在我操作中是必须设置,不然在clone过程中会报错中断。执行时间会很长,最好使用异步的方式执行。执行完成后会生成MyGit目录,已经是一个GIT本地仓库,如果执行结束目录里没有文件,说明中途报错了(我一直以为是要做其他操作才会检出)。
5.上传到GIT工程
- 其他资料里写的上传方法我用了一直不行,这里我用的是
cd myGit/
sudo git remote add origin git@host:example/code.git
sudo git add .
sudo git commit -m "Initial commit"
sudo git push -u origin master
进入clone生成的目录,依次执行命令,过程中如果报错,一是添加远程仓库可能需要git用户权限,在url中带上用户名密码,二是本地没权限执行命令,加上sudo或者root用户就行。