1) 将远程SVN仓库搬到本地(见:将远程SVN仓库搬到本地)
假设最终要转换的SVN仓库为file:///D:/ane-lab
2) 使用git svn clone命令开始转换
git svn clone file:///D:/ane-lab -T trunk -b branches -t tags
open repository ‘file:///D:/ane-lab’: Expected FS format ‘2’; found format ‘6’
at /usr/lib/perl5/site_perl/Git/SVN.pm line 310
第一步里的 服务程序是1.4.x版本的svnserve或mod_dav_svn,版本库通过1.8.x版本的svnadmin或TortoiseSVN创建的,会产生这个问题
If you access your Subversion repository using a network protocol (such as svn://) instead of local file access, then things should work properly for you. It appears as though you’re asking git-svn to access the repository directly, causing the problem you’ve shown. The Subversion network protocols are more resilient to older clients connecting.
不方便更换版本
可以直接用network协议的地址,例如:ssh://,svn://
实在不行不用本地库:
git svn clone http://ane-lab.googlecode.com/svn/ -T trunk -b branches -t tags
相当于针对所提供的 URL 运行了两条命令git svn init加上gitsvn fetch。因Git需要提取每一个版本,每次一个,再逐个提交。
-T trunk -b branches -t tags告诉Git该Subversion仓库遵循了基本的分支和标签命名法则。如果你的主干(trunk,相当于Git里的master分支,代表开发的主线)、分支或者标签以不同的方式命名,则应做出相应改变。由于该法则的常见性,可以使用-s来代替整条命令,它意味着标准布局(s是Standard layout的首字母),也就是前面选项的内容。下面的命令有相同的效果:
git svn clone file:///D:/ane-lab -s
用“git show-ref”就可以看到转换后Git仓库的相关情况,结果类似如下:
git show-ref
C:\Users\Administrator\Documents\GitHub\svn [master]> git show-ref
03ad1cde113d2c9e00f98bbbcc59b0057224740b refs/heads/master
03ad1cde113d2c9e00f98bbbcc59b0057224740b refs/remotes/trunk
3) 获取SVN服务器的最新更新到转换后的Git仓库(这步通常在连续的转换过程中就没必要了)
git svn rebase
C:\Users\Administrator\Documents\GitHub\svn [master]> git svn rebase
Current branch master is up to date.
4) 转换SVN仓库的svn:ignore属性到Git仓库的.gitignore文件
git svn create-ignore
该命令自动建立对应的.gitignore文件,以便下次提交的时候可以包含它。如果在生成.gitignore文件前想先查看一下,运行命令“git svn show-ignore”即可。
5) 转换SVN的标签为Git标签
cp -Rf .git/refs/remotes/tags/ .git/refs/tags/
rm -Rf .git/refs/remotes/tags
该命令将原本以 tag/ 开头的远程分支的索引变成真正的(轻巧的)标签。
这个在Window下试过不行,报”cp: cannot stat `.git/refs/remotes/tags/‘: No such file or directory“的错误,可以使用如下两个标准命令处理:
git tag tagname tags/tagname —-用指定的分支创建一个Git标签
git branch -r -d tags/tagname —-删除指定的远程分支
6) 转换SVN的分支为Git分支
cp -Rf .git/refs/remotes/* .git/refs/heads/
rm -Rf .git/refs/remotes
该命令把refs/remotes下面剩下的索引变成Git本地分支
7) 最后把转换后的本地Git仓库推到公共的Git服务器
git remote add origin https://github.com/austgl/ane-lab.git
git push origin master –tags
所有的标签和主干现在都应该整齐干净的躺在新的Git服务器里了。如果要将分支也同步到远程Git服务器,将–tags改为–all。