使用 Git-SVN 命令管理 SVN 项目

基于历史问题,大量项目使用 SVN 进行版本管理,而 Git 作为 SVN 的替代品,可以方便地管理 SVN 项目。

管理的基础,是 GitSVN 之间的转换,即 Git-SVN 命令。

Git-SVN 命令

  1. 初始化 Git 仓库
$ git svn init https://svn.example.com/svn/repo -T trunk -b branches -t tags --username zhangsan
  1. 更新 Git 仓库
$ git svn fetch
  1. 建立自己的 Git 分支
$ git branch my_branch
  1. 在自己的 Git 分支上开发
$ git checkout my_branch
$ git add file1 file2
$ git commit -m "commit message"
  1. 同步 Git 分支到 SVN 仓库
$ git svn fetch
$ git svn dcommit

特别操作

如果想在自己分支和 SVN 仓库之间保持差异,可在建立分支后,在自己分支上进行虚拟合并,造出合并点。

# hash id 为 git-svn fetch 后,git log 中显示的最新 commit id
$ git merge -s ours hashid

参考资料

[1] Git-SVN