温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

svn迁移至git

发布时间:2020-06-24 22:23:59 来源:网络 阅读:1221 作者:lylspecter 栏目:移动开发

svn 版本库的迁移,只要svn 库为标准目录(trunk、branches、tags)按照git官方文档基本都可以完成。

这里说说我所迁移的非标准目录结构的svn 库

svn 库里有part1目录,part1目录下又分为:code、UI等等,对于这种非标准目录结构,主干就是part1,没有分支,没有标签。

而code下面又分为android、ios目录,目录内才分trunk、tags、branch,这种目录层级结构……


对于以上非标准目录结构,我采用的是先git svn到本地,并提交到git仓库一个完整的版本,然后再将各目录层级进行拆分为独立标准目录结构svn库,然后再将各个库git svn到本地,再提交到git库。

说的可能有些绕,具体来操作下

全局假设:

原svn库地址:file:///home/svn1/

拆分后的标准库地址:file:///home/svn2/$svn/

原svn库对应的git地址:https://git.example.com/dev/oldsvn.git

拆分后对应的git地址:git@git.example.com/dev/$svn.git


注:$svn以具体目录或库名命名

目录结构:

part1:

    code:

        android:trunk、tags、branches

        ios:trunk、tags、branches

    UI


将原svn库克隆到本地:

对于标准目录结构含有其它自定义的目录,也可采用此方式,只需将trunk设置为自定义的目录名即可

git svn clone file:///home/svn/ \
--authors-flie=users.txt  --no-metadata --trunk=part1 oldsvn

选项含义:

    --authors-file: 指定svn和git用户对应关系

    --no-metadata: 告诉 git svn 不要包括 Subversion 通常会导入的元数据

    --trunk: 主干名

注:这里没有tags和branches所以不加 --tags --branch选项,也不用-s 选项代替。非标准目录结构,实际存在什么就指定什么,不存在不指定。

        在clone过程中,可能会有含‘gc‘ 的提示,遇见则‘git gc --prune=now',然后'git svn fetch' 继续clone

成功后,克隆的git 仓库结构对应为:

    code:

        android:trunk、tags、branches

        ios:trunk、tags、branches

    UI

将此提交到git 仓库,作为旧版本库,便于查看原svn历史提交修改。

git remote add origin https://git.example.com/dev/oldsvn.git
git push origin --all


对于多层级的目录结构,如现在需要将part1:conde:ios 的库迁移到git 上

首先,将ios 目录拷贝到svn库的根目录,既与part1同级,目录机构如下:

part1:

    code:

        android:trunk、tags、branches

        ios:trunk、tags、branches

    UI

android:trunk、tags、branches

ios:trunk、tags、branches

UI:


这样在通过‘git svn clone‘ 的时候,就可以指定trunk为ios了

git svn clone file:///home/svn/ \
--authors-flie=users.txt  --no-metadata --trunk=ios --branch=branches --tags=tags ios


将标签变为合适的 Git 标签

$ cp -Rf .git/refs/remotes/origin/tags/* .git/refs/tags/
$ rm -Rf .git/refs/remotes/origin/tags

这会使原来在 remotes/origin/tags/ 里的远程分支引用变成真正的(轻量)标签。

接下来,将 refs/remotes 下剩余的引用移动为本地分支:

$ cp -Rf .git/refs/remotes/* .git/refs/heads/$ rm -Rf .git/refs/remotes

将你的新 Git 服务器添加为远程仓库并推送到上面

git remote add origin git@git.example.com/dev/ios.git
git branch -r
git push origin --all


在变更svn目录的过程中可能会耗费很多时间,因此也可保持原svn目录结构,进行克隆

git svn clone file:///home/svn/part1/code/android \
--authors-flie=users.txt  --no-metadata -T trunk -t tags -b branches android

使用此方式,可能会出现未知问题,我遇到的是

fatal: refs/remotes/trunk: not a valid SHA1

以上问题尚未解决

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI