SVN如何迁移到Git?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SVN如何迁移到Git?相关的知识,希望对你有一定的参考价值。
最近在使用华为软件开发云进行开发项目管理,目前华为软件开发云支持500M的免费项目空间,而且还可以在线编译和构建,不用担心开发环境和生产环境的不同,很好的体现了DevOps的开发理念.
之前一直是用svn做代码管理,而华为软件开发云是使用目前国外比较流行的Git进行代码版本控制.在网上查询了迁移方式,发现Git本身有命令可以直接克隆SVN的代码库,而且迁移后能保持原SVN的提交记录.以下是总结的SVN代码库向华为软件开发云迁移的过程.
主要步骤
1.通过git svn clone命令将SVN代码库克隆至本地
2.华为开发云创建代码仓库,获取Git仓库地址
3.本地新建test分支,提交后合并至master分支.开发云代码库中根据引导完成代码合并. (新建分支合并的原因后面会讲.)
准备条件
1.准备要迁移的svn代码库地址;本地安装Git
2.登录华为软件开发云(https://www.hwclouds.com/devcloud/),并已创建好项目.
完整迁移流程
1.通过git svn clone命令将SVN代码库克隆至本地
$ git svn clonehttps://SVN服务器地址/ibeisi.iPMSystem/ --no-metadata --trunk=trunk
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-f70ac90fed6f92b2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#查看SVN提交记录
$ cd ibeisi.iPMSystem/
$ git log
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-55fe421f535c5ba5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2.华为软件开发云创建代码仓库,获取Git仓库地址
代码仓库创建好之后,需根据在线帮助,添加SSH秘钥,步骤很详细,此处就不作赘述.
SSH秘钥主要是本地与华为软件开发云代码库的一个管理,无需每次通过用户名和密码验证
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-1ae747822d0df629.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-0d85baa9c127eeb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-ff342b7ac5faff77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-32ba5d75e9d53b6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-74bc15819c103585.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-b73e1015f7cb9818.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-048454994e5547af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
打开代码仓库,拷贝代码仓库地址
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-741433caf8a0158f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3.根据步骤2中获取到的代码仓库地址,本地添加远程仓库地址
$ git remote add origin
[email protected]:3bf9c1ed148142d880d759e80100b923/iPMSystem.git
#拉取远程分支
$ git pull
可以看到代码仓库中默认已建好主分支,如果无需保留SVN原提交记录,可以直接将代码通过master分支进行提交(commit)和推送(push);但我想保留原提交记录,所以下面以新建分支合并到master的方式进行代码上传。
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-639b95ceefc61f65.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.本地新建分支test,并发起与master分支合并请求
$ git branch test
#checkout命令会让当前切换到test分支,及后续操作都只影响test分支
$ git checkout test
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-a4a7b76fc6645b9d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#新建空文件,原因是若没有更改git不会进行push操作
$ vi test.txt
#空文件添加至分支中
$ git add .
#git的commit命令只是在本地提交,并不会上传至代码库.
$ git commit -m "上传代码新建缓存分支"
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-2b5675cc4216f50f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#通过以下push命令可以发起test与master分支合并请求.
$ git push--set-upstream origin test
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-486d20c2bb412188.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5.刷新代码库页面(或重新打开代码库),可以看到合并请求的处理指引,按照指引操作即可完成合并.
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-8cbda0a17a37375f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-8bd9b421b0573fae.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-b0d61c49b250a8af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-cec9efbf2923ea5b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-73f8f64b0837ffe5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-ccabf54186be4e45.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
可以看到原svn代码库的提交记录都被完整保存了下来.
![技术分享](http://upload-images.jianshu.io/upload_images/5609636-68e075197994faa4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
至此, svn代码库可以说完整地迁移到了华为软件开发云的CodeHub中。
以上是关于SVN如何迁移到Git?的主要内容,如果未能解决你的问题,请参考以下文章