由于习惯了 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
git svn fetch
或者
git svn clone
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
-t
-b
-s [--stdlayout] <采用标准 SVN 目录结构trunk,branches,tags>
--prefix=
-r
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.仓库配置文件
存储位置
[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
--destination, -d
--dry-run, -n
--message, -m
--parents
--tag, -t
--username
clone Initialize and fetch revisions
--add-author-from
--authors-file, -A
--authors-prog
--branches, --b=s@
--config-dir
--follow-parent, --follow!
--ignore-paths
--ignore-refs
--include-paths
--localtime
--log-window-size
--minimize-url, --m!
--no-auth-cache
--no-checkout
--no-metadata
--placeholder-filename
--prefix
--preserve-empty-dirs
--quiet, --q+
--repack-flags, --repack-args, --repack-opts
--repack
--revision, -r
--rewrite-root
--rewrite-uuid
--shared
--stdlayout, -s
--tags, --t=s@
--template
--trunk, -T
--use-log-author
--use-svm-props
--use-svnsync-props
--username
commit-diff Commit a diff between two trees
--copy-similarity, -C
--edit, -e
--file, -F
--find-copies-harder
-l
--message, -m
--revision, -r
--rmdir
create-ignore Create a .gitignore per svn:ignore
--revision, -r
dcommit Commit several diffs to merge with upstream
--add-author-from
--authors-file, -A
--authors-prog
--commit-url
--config-dir
--copy-similarity, -C
--dry-run, -n
--edit, -e
--fetch-all, --all
--find-copies-harder
--follow-parent, --follow!
--ignore-paths
--ignore-refs
--include-paths
--interactive, -i
-l
--localtime
--log-window-size
--mergeinfo
--merge, -m, -M
--no-auth-cache
--no-checkout
--no-rebase
--quiet, --q+
--repack-flags, --repack-args, --repack-opts
--repack
--revision, -r
--rmdir
--set-svn-props
--strategy, -s
--use-log-author
--username
--verbose, -v
fetch Download new revisions from SVN
--add-author-from
--authors-file, -A
--authors-prog
--config-dir
--fetch-all, --all
--follow-parent, --follow!
--ignore-paths
--ignore-refs
--include-paths
--localtime
--log-window-size
--no-auth-cache
--no-checkout
--parent, -p
--quiet, --q+
--repack-flags, --repack-args, --repack-opts
--repack
--revision, -r
--use-log-author
--username
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
--ignore-paths
--ignore-refs
--include-paths
--minimize-url, --m!
--no-auth-cache
--no-metadata
--prefix
--rewrite-root
--rewrite-uuid
--shared
--stdlayout, -s
--tags, --t=s@
--template
--trunk, -T
--use-svm-props
--use-svnsync-props
--username
log Show commit logs
--authors-file, -A
--color
--incremental
--limit
--non-recursive
--oneline
--pager
--revision, -r
--show-commit
--verbose, -v
migrate Migrate configuration/metadata/layout from
previous versions of git-svn
--config-dir
--ignore-paths
--ignore-refs
--include-paths
--minimize
--no-auth-cache
--username
mkdirs recreate empty directories after a checkout
--revision, -r
propget Print the value of a property on a file or directory
--revision, -r
proplist List all properties of a file or directory
--revision, -r
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
--authors-prog
--config-dir
--dry-run, -n
--fetch-all, --all
--follow-parent, --follow!
--ignore-paths
--ignore-refs
--include-paths
--localtime
--local, -l
--log-window-size
--merge, -m, -M
--no-auth-cache
--no-checkout
--preserve-merges, -p
--quiet, --q+
--repack-flags, --repack-args, --repack-opts
--repack
--strategy, -s
--use-log-author
--username
--verbose, -v
reset Undo fetches back to the specified SVN revision
--parent, -p
--revision, -r
set-tree Set an SVN repository to a git tree-ish
--add-author-from
--authors-file, -A
--authors-prog
--config-dir
--copy-similarity, -C
--edit, -e
--find-copies-harder
--follow-parent, --follow!
--ignore-paths
--ignore-refs
--include-paths
-l
--localtime
--log-window-size
--no-auth-cache
--no-checkout
--quiet, --q+
--repack-flags, --repack-args, --repack-opts
--repack
--rmdir
--stdin
--use-log-author
--username
show-externals Show svn:externals listings
--revision, -r
show-ignore Show svn:ignore listings
--revision, -r
tag Create a tag in the SVN repository
--commit-url
--destination, -d
--dry-run, -n
--message, -m
--parents
--username
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.