用GIT操作SVN

由于習(xí)慣了 GIT 版本管理,切回 SVN 落差太大.下面總結(jié)用 GIT 操作 SVN.

一.原理

1.本地倉庫以 GIT 方式管理,遠程以 SVN 方式管理.

2.每個 GIT 分支都有唯一的SVN分支(根),推送服務(wù)器時,只能推到這個 SVN 分支,不能推送到新建 SVN 分支.

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

二.實踐

1.環(huán)境配置

1.1.安裝GIT(略).

1.2.安裝 SourceTree(可選.略)

2.克隆 SVN 到 GIT

2.1.命令

git svn init <SVN_PATH> <LOCAL_PATH> [可選參數(shù)]

git svn fetch

或者

git svn clone <SVN_PATH> <LOCAL_PATH> [可選參數(shù)]

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

--使用標準結(jié)構(gòu)初始化 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.參數(shù)說明

-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 目錄結(jié)構(gòu)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 服務(wù)器徑徑,只能添加一個星號(*)通配符,位置可以隨意添加.(多個時會報錯)

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.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市旱幼,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,378評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異凡恍,居然都是意外死亡,警方通過查閱死者的電腦和手機怔球,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評論 2 382
  • 文/潘曉璐 我一進店門嚼酝,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人竟坛,你說我怎么就攤上這事革半”ǎ” “怎么了?”我有些...
    開封第一講書人閱讀 152,702評論 0 342
  • 文/不壞的土叔 我叫張陵又官,是天一觀的道長延刘。 經(jīng)常有香客問我,道長六敬,這世上最難降的妖魔是什么碘赖? 我笑而不...
    開封第一講書人閱讀 55,259評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮外构,結(jié)果婚禮上普泡,老公的妹妹穿的比我還像新娘。我一直安慰自己审编,他們只是感情好撼班,可當(dāng)我...
    茶點故事閱讀 64,263評論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著垒酬,像睡著了一般砰嘁。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上勘究,一...
    開封第一講書人閱讀 49,036評論 1 285
  • 那天矮湘,我揣著相機與錄音,去河邊找鬼口糕。 笑死缅阳,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的景描。 我是一名探鬼主播十办,決...
    沈念sama閱讀 38,349評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼超棺!你這毒婦竟也來了橘洞?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,979評論 0 259
  • 序言:老撾萬榮一對情侶失蹤说搅,失蹤者是張志新(化名)和其女友劉穎炸枣,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體弄唧,經(jīng)...
    沈念sama閱讀 43,469評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡适肠,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,938評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了候引。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片侯养。...
    茶點故事閱讀 38,059評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖澄干,靈堂內(nèi)的尸體忽然破棺而出逛揩,到底是詐尸還是另有隱情柠傍,我是刑警寧澤,帶...
    沈念sama閱讀 33,703評論 4 323
  • 正文 年R本政府宣布辩稽,位于F島的核電站惧笛,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏逞泄。R本人自食惡果不足惜患整,卻給世界環(huán)境...
    茶點故事閱讀 39,257評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望喷众。 院中可真熱鬧各谚,春花似錦、人聲如沸到千。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽憔四。三九已至膀息,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間加矛,已是汗流浹背履婉。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工煤篙, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留斟览,地道東北人。 一個月前我還...
    沈念sama閱讀 45,501評論 2 354
  • 正文 我出身青樓辑奈,卻偏偏與公主長得像苛茂,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子鸠窗,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,792評論 2 345

推薦閱讀更多精彩內(nèi)容

  • 一. 介紹SubGit是用java語言編寫的妓羊。SubGit是一種subversion與git代碼庫之間雙向同步工具...
    Albert陳凱閱讀 891評論 0 1
  • Svn vs Git 詳解可見: Git 和 SVN 之間的五個基本區(qū)別、Svn與Git的區(qū)別廢話不多說直接開始教...
    叛逆點起一根煙閱讀 1,767評論 0 1
  • &開發(fā)過程中離不開源代碼的管理稍计, 目地:為了解決在軟件開發(fā)過程中躁绸,由源代碼引發(fā)的各種蛋疼、繁瑣的問題臣嚣。 目前開發(fā)使...
    早起的蟲兒子被鳥吃閱讀 2,412評論 0 16
  • git 使用筆記 git原理: 文件(blob)對象净刮,樹(tree)對象,提交(commit)對象 tree對象 ...
    神刀閱讀 3,757評論 0 10
  • 無意間看到朋友分享的一段話:請您閉上眼睛……想象一下硅则,2047年淹父,30年過后,您坐在空無一人的房間怎虫,臃腫老態(tài)...
    莫捉妖妖閱讀 276評論 0 0