由于习惯了 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.