用GIT操作SVN

由于习惯了 GIT 版本管理,切回 SVN 落差太大.下面总结用 GIT 操作 SVN.

一.原理

1.本地仓库以 GIT 方式管理,远程以 SVN 方式管理.

2.每个 GIT 分支都有唯一的SVN分支(根),推送服务器时,只能推到这个 SVN 分支,不能推送到新建 SVN 分支.

3.采用GIT 提供了 git-svn 命令工具可以操作 SVN.

二.实践

1.环境配置

1.1.安装GIT(略).

1.2.安装 SourceTree(可选.略)

2.克隆 SVN 到 GIT

2.1.命令

git svn init <SVN_PATH> <LOCAL_PATH> [可选参数]

git svn fetch

或者

git svn clone <SVN_PATH> <LOCAL_PATH> [可选参数]

2.2.例子

git svn clone 命令是 git svn init 与 git svn fetch 命令的合并.

git svn clone -T trunk -b branches -t tags https://github.com/xetorthio/jedis.git /develop/code/jedis

--使用标准结构初始化 GIT-SVN仓库.

git svn init https://github.com/xetorthio/jedis.git /develop/code/jedis -s

--获取指定变更集代码(注间:若SVN 变更集过多,获取整个变更需要花费几天的时间,因为每个变更都会拉取一次)

git svn fetch --revision 5572:HEAD

输出

r5572 = b17002fa989eaf6d5e86d91cae5d75458eec0540 (refs/remotes/origin/trunk)

...

r5573 = 0eb64f068b12634cbb27dbfee87cfdd6a539d58d (refs/remotes/origin/2.10)

...

r5574 = 82cd4fa8074f33bcbea967f74eb18c1a32304c90 (refs/remotes/origin/2.10)

Checked out HEAD:

https://github.com/xetorthio/jedis.git/trunk r5572

-T trunk -b branches -t tags 用于指定 SVN 主干,分支,标记目录.如果是标准目录,则可以使用-s或者--stdlayout


查看仓库分支信息

git branch -a

* master

remotes/origin/2.10

remotes/origin/trunk


2.3.参数说明

-T<trunk_subdir> [--trunk=<trunk_subdir>] <指定 SVN trunk目录>

-t<tags_subdir>  [--tags=<tags_subdir>] <指定SVN tags根目录>

-b<branches_subdir> [--branches=<branches_subdir>] <指定 SVN branches根目录>

-s [--stdlayout] <采用标准 SVN 目录结构trunk,branches,tags>

--prefix=<prefix> <refs/remotes/$prefix/用于指定远程引用前辍,默认为 origin/>

-r <arg> [--revision <arg>]  <下载指定范围的版本,支持后机的格式$NUMBER, $NUMBER1:$NUMBER2 (numeric ranges), $NUMBER:HEAD, and BASE:$NUMBER>

3.提交

3.1.命令

git commit(就是GIT操作)

4.推送

4.1.命令

git svn dcommit

6.分支建立

6.1.命令

git svn branch

git svn tag

7.更新

7.1.命令

git svn rebase

8.仓库配置文件

存储位置<git_dir>/config

[svn-remote "project-a"] url = http://server.org/svn fetch = trunk/project-a:refs/remotes/project-a/trunk branches = branches/*/project-a:refs/remotes/project-a/branches/* branches = branches/release_*:refs/remotes/project-a/branches/release_* branches = branches/re*se:refs/remotes/project-a/branches/* tags = tags/*/project-a:refs/remotes/project-a/tags/*

注意:

1:冒号右边为本地GIT引用,只能在引用最右添加一个星号(*)通配符.

2.冒号左边是SVN 服务器径径,只能添加一个星号(*)通配符,位置可以随意添加.(多个时会报错)

3.分支和标记也可以使用逗号分隔的集合,例如:

[svn-remote "huge-project"] url = http://server.org/svn fetch = trunk/src:refs/remotes/trunk branches = branches/{red,green}/src:refs/remotes/project-a/branches/* tags = tags/{1.0,2.0}/src:refs/remotes/project-a/tags/*

4.支持多个 fetch,branches,tags 配置.

三.命令大全



Available commands:

blame Show what revision and author last modified each line of a file

--git-format

branch Create a branch in the SVN repository

--commit-url <arg>

--destination, -d <arg>

--dry-run, -n

--message, -m <arg>

--parents

--tag, -t

--username <arg>

clone Initialize and fetch revisions

--add-author-from

--authors-file, -A <arg>

--authors-prog <arg>

--branches, --b=s@

--config-dir <arg>

--follow-parent, --follow!

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

--localtime

--log-window-size <num>

--minimize-url, --m!

--no-auth-cache

--no-checkout

--no-metadata

--placeholder-filename <arg>

--prefix <arg>

--preserve-empty-dirs

--quiet, --q+

--repack-flags, --repack-args, --repack-opts <arg>

--repack <num>

--revision, -r <arg>

--rewrite-root <arg>

--rewrite-uuid <arg>

--shared <arg>

--stdlayout, -s

--tags, --t=s@

--template <arg>

--trunk, -T <arg>

--use-log-author

--use-svm-props

--use-svnsync-props

--username <arg>

commit-diff Commit a diff between two trees

--copy-similarity, -C <num>

--edit, -e

--file, -F <arg>

--find-copies-harder

-l <num>

--message, -m <arg>

--revision, -r <arg>

--rmdir

create-ignore Create a .gitignore per svn:ignore

--revision, -r <num>

dcommit Commit several diffs to merge with upstream

--add-author-from

--authors-file, -A <arg>

--authors-prog <arg>

--commit-url <arg>

--config-dir <arg>

--copy-similarity, -C <num>

--dry-run, -n

--edit, -e

--fetch-all, --all

--find-copies-harder

--follow-parent, --follow!

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

--interactive, -i

-l <num>

--localtime

--log-window-size <num>

--mergeinfo <arg>

--merge, -m, -M

--no-auth-cache

--no-checkout

--no-rebase

--quiet, --q+

--repack-flags, --repack-args, --repack-opts <arg>

--repack <num>

--revision, -r <num>

--rmdir

--set-svn-props <arg>

--strategy, -s <arg>

--use-log-author

--username <arg>

--verbose, -v

fetch Download new revisions from SVN

--add-author-from

--authors-file, -A <arg>

--authors-prog <arg>

--config-dir <arg>

--fetch-all, --all

--follow-parent, --follow!

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

--localtime

--log-window-size <num>

--no-auth-cache

--no-checkout

--parent, -p

--quiet, --q+

--repack-flags, --repack-args, --repack-opts <arg>

--repack <num>

--revision, -r <arg>

--use-log-author

--username <arg>

find-rev Translate between SVN revision numbers and tree-ish

-A, --after

-B, --before

gc Compress unhandled.log files in .git/svn and remove index files in .git/svn

info Show info about the latest SVN revision

on the current branch

--url

init Initialize a repo for tracking (requires URL argument)

--branches, --b=s@

--config-dir <arg>

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

--minimize-url, --m!

--no-auth-cache

--no-metadata

--prefix <arg>

--rewrite-root <arg>

--rewrite-uuid <arg>

--shared <arg>

--stdlayout, -s

--tags, --t=s@

--template <arg>

--trunk, -T <arg>

--use-svm-props

--use-svnsync-props

--username <arg>

log Show commit logs

--authors-file, -A <arg>

--color

--incremental

--limit <num>

--non-recursive

--oneline

--pager <arg>

--revision, -r <arg>

--show-commit

--verbose, -v

migrate Migrate configuration/metadata/layout from

previous versions of git-svn

--config-dir <arg>

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

--minimize

--no-auth-cache

--username <arg>

mkdirs recreate empty directories after a checkout

--revision, -r <num>

propget Print the value of a property on a file or directory

--revision, -r <num>

proplist List all properties of a file or directory

--revision, -r <num>

propset Set the value of a property on a file or directory - will be set on commit

rebase Fetch and rebase your working directory

--add-author-from

--authors-file, -A <arg>

--authors-prog <arg>

--config-dir <arg>

--dry-run, -n

--fetch-all, --all

--follow-parent, --follow!

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

--localtime

--local, -l

--log-window-size <num>

--merge, -m, -M

--no-auth-cache

--no-checkout

--preserve-merges, -p

--quiet, --q+

--repack-flags, --repack-args, --repack-opts <arg>

--repack <num>

--strategy, -s <arg>

--use-log-author

--username <arg>

--verbose, -v

reset Undo fetches back to the specified SVN revision

--parent, -p

--revision, -r <arg>

set-tree Set an SVN repository to a git tree-ish

--add-author-from

--authors-file, -A <arg>

--authors-prog <arg>

--config-dir <arg>

--copy-similarity, -C <num>

--edit, -e

--find-copies-harder

--follow-parent, --follow!

--ignore-paths <arg>

--ignore-refs <arg>

--include-paths <arg>

-l <num>

--localtime

--log-window-size <num>

--no-auth-cache

--no-checkout

--quiet, --q+

--repack-flags, --repack-args, --repack-opts <arg>

--repack <num>

--rmdir

--stdin

--use-log-author

--username <arg>

show-externals Show svn:externals listings

--revision, -r <num>

show-ignore Show svn:ignore listings

--revision, -r <num>

tag Create a tag in the SVN repository

--commit-url <arg>

--destination, -d <arg>

--dry-run, -n

--message, -m <arg>

--parents

--username <arg>


GIT_SVN_ID may be set in the environment or via the --id/-i switch to an

arbitrary identifier if you're tracking multiple SVN branches/repositories in

one git repository and want to keep them separate. See git-svn(1) for more

information.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 162,710评论 4 376
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,839评论 2 308
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 112,295评论 0 255
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,776评论 0 223
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 53,198评论 3 297
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 41,074评论 1 226
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,200评论 2 322
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,986评论 0 214
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,733评论 1 250
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,877评论 2 254
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,348评论 1 265
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,675评论 3 265
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,393评论 3 246
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,209评论 0 9
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,996评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 36,212评论 2 287
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 36,003评论 2 280

推荐阅读更多精彩内容