使用 subgit 镜像进行单向同步

Use subgit mirror for one way sync

我设置了 subgit 以将一个 assembla svn 存储库镜像到 git。我只想使用 svn->git 方式。无论如何,我无权提交 svn repo,因此 subgit 在尝试同步回 svn (git->svn) 时会出现错误消息。有什么办法可以做到这一点?

无法支持推送某些 Git 分支而不将它们转换为 SVN,同时使它们与 SVN 分支保持同步。因此,解决方案是使用一组 Git 分支,同时保持另一组分支与 SVN 同步。那些同步的分支应该被手动周期性地合并到第一组的分支中。有几种方法可以使用 SubGit.

方法 1. 使用单独的命名空间。例如,您可以在使用 refs/heads/* 时将 refs/heads/svn/*refs/tags/svn/* 同步到 SVN。为此,请在 SubGit 配置文件中使用以下选项:

trunk = trunk:refs/heads/svn/master
branches = branches/*:refs/heads/svn/*
tags = tags/*:refs/tags/svn/*
shelves = shelves/*:refs/shelves/svn/*

所以当你克隆这样一个存储库时,SVN trunk 被翻译成 refs/remotes/origin/svn/master,你应该定期使用 git merge 手动合并该分支以使你的本地 refs/heads/master 或多或少与 SVN 保持同步。

方法 2. 自 SubGit 3.0(或 3.0.0-EAP 版本发布前)起,您可以将与 SVN 同步的所有分支限制为一个或几个分支(其他 branches/tags/shelves 选项已删除):

trunk = trunk:refs/heads/master
branches = branches/branch1:refs/heads/branch1
branches = branches/branch2:refs/heads/branch2

之后refs/heads/branch1refs/heads/branch2refs/heads/master会同步SVN,refs/heads/branch3不会。

方法 3. 自 SubGit 3.0(或 3.0.0-EAP 版本发布前)起,您可以从同步中排除一个或多个分支:

trunk = trunk:refs/heads/master
branches = branches/*:refs/heads/*
tags = tags/*:refs/tags/*
shelves = shelves/*:refs/shelves/*
excludeBranches = branches/nosync1
excludeBranches = branches/nosync2

此配置同步除 refs/heads/nosync1refs/heads/nosync2 之外的所有 refs/heads/*,因为如果同步它们,它们将被转换为 branches/nosync1branches/nosync2被忽略。

其实你并不局限于这些方法,你可以根据你的需要混合使用它们。