GIT版本控制 — GIT与SVN的相互转换 (三)
git-svn
git-svn用于Git和SVN的转换,可以把Git仓库迁移成SVN仓库,反之亦可。
详细介绍可见[1],或者命令行输入git-svn。
Bidirectional operation between a Subversion repository and git.
git svn can track a standard Subversion repository, following the common "trunk/branches/tags" layout,
with the --stdlayout option. It can also follow branches and tags in any layout with the -T/ -t/ -b options.
Once tracking a Subversion repository, the git repository can be updated from Subversion by thefetch
command and Subversion updated from git by the dcommit command.
Git迁移到SVN
把Git迁移到SVN?没错,还真有这种需求,虽然较少:)
Git has a feature to work with SVN repositories, git-svn, but that's intended to check out
existing code from SVN and work on it, not publishing an existing Git tree into a SVN repository.
(1) 依赖包
需要安装subversion-perl、perl-TermReadKey。
Git中带有git-svn,需要确定它的路径可在PATH中找到。
(2) 建立svn项目
在svn服务器中新建svn项目proj。
# svnadmin create proj
(3) svn项目的本地初次提交
# svn mkdir http://IP:PORT/svn/proj/trunk \
http://IP:PORT/svn/proj/branches \
http://IP:POPT/svn/proj/tags \
http://IP:PORT/svn/proj/docs -m "Initial import"
(4) 提交Git proj项目到SVN proj
进入Git proj项目。
# git-svn init -s http://IP:PORT/svn/proj // -s表示svn为标准布局
标准布局的意思就是:
trunk分支为:proj/trunk,可以用-T另外指定
branches分支为:proj/branches,可用-b另外指定
tags分支为:proj/tags,可用-t另外指定
# git-svn fetch // 获取SVN proj的更新
r1 = 79563196f21ce4699a04fa4ae24d0ca916bf3acf (refs/remotes/trunk)
trunk分支代表SVN proj的trunk分支
# git-svn dcommit // 提交Git proj的更新
注意!这个时候会报错:
Unable to determine upstream SVN information from HEAD history.
Perhaps the repository is empty. at /usr/local/git/libexec/git-core/git-svn line 852.
因为现在Git proj的commits不知道要放到SVN proj的哪个版本之后,即Git proj的这些提交要
放在SVN哪个版本之后(显然是放到SVN的初始提交之后,但是Git proj就是不知道,因为设计者
并不考虑把Git proj转为SVN proj的情况:)
以下是详细描述:
This fails since the git svn command can't figure out which commits to push: there's no link
between our original Git repository and the Subversion heads.
To fix this, we can use a Git graft to link them. We'll tell Git the commit which created the SVN
folder in which we want to store the project is the parent commit of the first commit in our Git
repository.
解决方法
# git show-ref trunk // 显示SVN proj trunk分支的HEAD,即r1
79563196f21ce4699a04fa4ae24d0ca916bf3acf refs/remotes/trunk
# git log --pretty=oneline master | tail -n 1 // 显示Git proj 的第一个commit
561c439a15f807b8d62551a0c64f939c15489899 initial import
# echo "561c439a15f807b8d62551a0c64f939c15489899 79563196f21ce4699a04fa4ae24d0ca916bf3acf" >> .git/info/grafts
把Git proj从561c43开始的提交,添加到SVN proj在795631之后的提交。
# git-svn dcommit // 提交Git proj的更新到SVN proj中
这个时候就把Git proj完整的转化成SVN proj,后者完全符合SVN的规范了。
(5) 把git分支提交到svn的分支
如果原来的git仓库不仅有master,还有其它分支,那么怎么把git的分支提交为svn的分支呢?
这个时候就要用到git rebase了。
过程如下:
在远端svn仓库中创建一个新分支。
# svn cp URL/trunk URL/branches/remote-branch
更新本端Git仓库。
# git-svn fetch
切换到本端的分支。
# git checkout local-branch
创建一个用于临时用的分支,其实和local-branch是一样的。
# git checkout -b temp-local-branch
关键点来了,把本端分支的所有修改,合并到远端分支。
# git rebase remotes/remote-branch
完成上一步以后,远端分支已经含有本端分支的所有commit。
接着可以把修改提交到svn仓库了。
# git svn dcommit
最后把本端的临时分支删除。
# git branch -D temp-local-branch
此时再查看svn仓库,就会发现branch/remote-branch已经是原来的git分支了。
不过svn分支的日志顺序,相较于原来git分支的可能会有所不同,这是由rebase引起的,正常现象。
(6) 从git分支更新svn分支
修改.git/config,添加远程分支:
[svn-remote "branch"]
url = URL/proj/branches/branch
fetch = :refs/remotes/branch
绑定本地分支和远程分支:
[branch "local-branch"]
remote = .
merge = refs/remotes/branch
修改了本地分支local-branch后,可以直接提交到远端svn的branch分支了。
# git-svn dcommit
SVN迁移到Git
相比之前介绍的Git迁移到SVN,SVN迁移到Git才是主流趋势,也更加容易,因为这是git-svn的主要目的。
同样用git-svn来完成迁移:
git-svn primarily can be used to checkout a Subversion repository to a local Git repo and then
push your changes back to the original Subversion repository.
克隆SVN仓库,可以使用-T trunk、-b branches、-t tags来指定对应分支,-s表示采用标准布局。
# git-svn clone -s URL/proj proj
相当于执行了git-svn init和git-svn fetch。
把SVN仓库的更新同步到Git。
# git-svn rebase
创建.gitignore文件。
# git-svn create-ignore
将Git的更新提交到SVN仓库。
# git-svn dcommit
Author
zhangskd @ csdn blog
Reference
[1]. https://www.kernel.org/pub/software/scm/git/docs/git-svn.html
[2]. http://plpatterns.com/post/234334879/how-to-convert-a-local-branch-in-git-to-a-remote
[3]. http://www.cnblogs.com/kym/archive/2010/08/12/1797937.html
GIT版本控制 — GIT与SVN的相互转换 (三)的更多相关文章
- Git版本控制 Git、github,gitlab相关操作
目录 关于版本控制 版本管理工具 集中式管理 分布式管理 git版本管理 git介绍 软件安装 Git工作状态 原理流程步骤 git基本操作 对文件进行修改 分支 共享仓库 创建共享仓库: 共享仓库上 ...
- 图文详解 : 什么是版本控制?Eclipse配置SVN和IDEA配置GIT教程
前言 虽然在工作中, VCS已然配置妥当, 我们敲好的业务只需要Commit&push提交就好, 但是不妨碍我们了解什么是版本控制, 为什么要使用这类工具? ps.最近项目里的小伙伴想在自己家 ...
- Git版本控制工具(三)----远程仓库GitHub的使用
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- 版本控制比较cvs,svn,git
版本控制比较cvs,svn,git 几个重要概念: 版本库模型(Repository model):描述了多个源码版本库副本间的关系,有客户端/服务器和分布式两种模式.在客户端/服务器模式下,每一用户 ...
- 版本控制-Git服务器搭建和常用命令使用
Git是目前世界上最先进的分布式版本控制系统(没有之一).使用Svn的请参考<版本控制-svn服务器搭建和常用命令(centos 6.3)>,下面介绍Git的常用命令 常用命令 简单版 升 ...
- Git版本控制与工作流
基本概念 Git是什么? Git是分布式版本控制系统,与SVN类似的集中化版本控制系统相比,集中化版本控制系统虽然能够令多个团队成员一起协作开发,但有时如果中央服务器宕机的话,谁也无法在宕机期间提交更 ...
- git版本控制工具(二)----本地版本库的常用操作
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- Git版本控制使用介绍
Git是什么? Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git与SVN的最主要的区别? Git是分布式的,SVN不是 Git没有一个全局的版本号,而SVN有 ...
- Git 版本控制工具(学习笔记)
GIT(分布式) 一.Git 初始版本控制工具 1. 安装Git Ubuntu系统下,打开shell界面,输入: sudo apt-get install git-core 之后回车输入密码,即可完 ...
随机推荐
- Answers to "Why are my jobs not running?"
from :https://community.oracle.com/thread/648581 This is one of the most common Scheduler questions ...
- Python练习之pillow
此系列意在记录于一些有趣的程序及对其的总结. 问题来源: https://github.com/Yixiaohan/show-me-the-code https://github.com/HT524/ ...
- /usr,/usr/local/ 还是 /opt ?
Linux 的软件安装目录是也是有讲究的,理解这一点,在对系统管理是有益的(好吧处女座表示完全不能接受不正确的路径选择,看着会不舒服的……) /usr:系统级的目录,可以理解为C:/Windows/, ...
- MyEclipse中查看struts_spring_hibernate源码
1.spring查看源码 首先下载对应的源码包 如:spring-framework-2.5.6-with-dependencies.zip 打开spring-framework-2.5.6\di ...
- 安卓高级 特效动画ExplosionField和 SmoothTransition
本教程所有图片为github上的所无法正常访问请科学上网 SmoothTransition 展示效果 github:源码地址 使用方法 你能通过一行代码使用上面所有的动画 @Override prot ...
- 《Non-Negative Matrix Factorization for Polyphonic Music Transcription》译文
NMF(非负矩阵分解),由于其分解出的矩阵是非负的,在一些实际问题中具有非常好的解释,因此用途很广.在此,我给大家介绍一下NMF在多声部音乐中的应用.要翻译的论文是利用NMF转录多声部音乐的开山之作, ...
- Android开发之手把手教你写ButterKnife框架(二)
欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52664112 本文出自:[余志强的博客] 上一篇博客Android开 ...
- Hadoop就业面试题
----------------------------------------------------------------------------- [申明:资料来源于互联网] 本文链接:htt ...
- Objective-C's Init Method
初始化器在其他面向对象的语言中(比如Java)指的是构造器. Objective-C同样拥有对象构造器在init形式的方法中.不管如何,在Objc中这些方法没有什么特殊的行为. 按照惯例,程序猿在in ...
- 两个无序数组分别叫A和B,长度分别是m和n,求中位数,要求时间复杂度O(m+n),空间复杂度O(1) 。
#include <iostream> using namespace std; /*函数作用:取待排序序列中low.mid.high三个位置上数据,选取他们中间的那个数据作为枢轴*/ i ...