欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

git svn使用指南

程序员文章站 2022-07-15 15:25:46
...

准备工作

准备远程svn仓库

$ svn info
Path: .
Working Copy Root Path: /Users/jack/workspace/qiubite
URL: http://xxxxxx.net/svn/xxxx/qiubite/code/test
Relative URL: ^/qiubite/code/test
Repository Root: http://xxxxxx.net/svn/xxxx
  • svn目录结构
    ├── branches
    │ ├── a
    │ │ └── 1.txt
    │ └── b
    │ └── 1.txt
    ├── tags
    └── trunk
    └── 1.txt

5 directories, 3 files

初始化本地git仓库

git svn init

git svn init http://xxxxx.net/svn/xxxxx/qiubite/code/test -s --prefix=svn/

  • 参数说明

    1. -s 告诉 Git 该 Subversion 仓库遵循了基本的分支和标签命名法则,也就是标准布局。如果你的主干(trunk,相当于非分布式版本控制里的master分支,代表开发的主线),分支(branches)或者 标签(tags)以不同的方式命名,则应做出相应改变。
      -s参数其实是-T trunk -b branches -t tags的缩写,这些参数告诉git这些文件夹与git分支、tag、master的对 应关系。

    2. –prefix=svn/ 给svn的所有remote名称增加了一个前缀svn,这样比较统一,而且可以防止warning: refname ‘xxx’ is ambiguous.

    如果你此时使用

    	$ git svn rebase
    	fatal: bad revision 'HEAD'
    	rev-list --first-parent --pretty=medium HEAD --: command returned error: 128
    

    实际上是你刚刚clone的仓库没有分支
    git branch -a是空的的,这个你可以不用管它,如果想解决,

    	echo 11 >1.txt
    	git add 1.txt
    	git commit -m'first'
    

    再次git branch -a你就会神奇的发现有* master

git本地关联svn远程仓库

  1. .git/config现在的内容
[svn-remote "svn"]
    url = http://xxxx.net/svn/xxxx/qiubite
    fetch = code/test/trunk:refs/remotes/svn/trunk
    branches = code/test/branches/*:refs/remotes/svn/*
    tags = code/test/tags/*:refs/remotes/svn/tags/*
  1. 关联svn
$ git svn rebase
Unable to determine upstream SVN information from working tree history

因为你的git branch -a中没有关联到svn 的remotes分支
解决办法

$ git svn fetch
	A	1.txt
	A	b.txt
r685 = 62a1127de0516a26ea34a29cfcba6a9df86034ac (refs/remotes/svn/trunk)
$ git branch -a
* master
  remotes/svn/a
  remotes/svn/b
  remotes/svn/trunk
$ git rebase --onto=svn/trunk --root master
First, rewinding head to replay your work on top of it...
Applying: ninit
$ git svn rebase
Current branch master is up to date.
  1. git svn fetch rHEAD时有一个超级大坑,你使用命令后居然什么反应都没有,原因是没有拉到svn的HEAD的内容,解决方法在svn中随便commit一下,你就能拉到内容了
  2. 你可能还会一种情况你fetch下来的svn分支不是trunk而是其他分支,有2种原因第一个你的svn最后一次提交是其他分支,第二个你svn最后一次提交是从git的非master分支提交的

使用

  • 更新代码
    git svn fetch
    git svn rebase
  • 提交到svn
    git add .
    git commit -m''
    git svn dcomit
    其余操作和git类似

git rebase的详细使用和作用科参考
本文参考了

  1. https://www.cnblogs.com/h2zZhou/p/6136948.html
  2. https://blog.csdn.net/zzxiang1985/article/details/75212244
相关标签: git svn