使用 git 捆绑包来同步气隙回购

Using git bundle to synch airgapped repos

我运行遇到一个问题,我想同步 2 个未通过网络连接的存储库。我已经使用 git 包在两者之间进行同步,但是 运行 变成了一个极端情况。

我正在通过以下方式创建 git 包:

git bundle create --since=<timestamp of lastBundle> --all <my_bundle_path>

其中 <timestamp of lastBundle> 是从与 lastBundle 标记关联的提交时间中选取的。这允许我只捆绑增量并获取所有分支中的所有新提交。

极端情况是这种特定情况发生的时间

master               2017-12-4 <dev who committed c2 finally gets around to pushing it to origin>
|\
| \
|  c3 <lastBundle>   2017-12-3 <commit that was synched>
|   |
c2  |                2017-12-2 <commit from dev, timestamped to when s/he committed it to their local repo>
 \  |
  \ |
   c1                2017-12-1 <base commit>

lastBundle 已同步,对应于气隙回购的最新参考,但有人在他们自己的本地副本中提交 c2 时间早于 c3回购并没有立即将参考推送到原点。因此,下次我捆绑从 lastBundle 开始的每个提交并将其放在驱动器上,将其加载到另一台机器上时,它无法验证,因为 c2 不在捆绑包中,只有它合并到大师.

我查看了 git merge-base 看是否可以找到一个共同的祖先,并使用它来代替。虽然这可以完成这项工作,但我认为我需要为每个分支添加一个 lastBundle 标记才能使其正常工作,因为这种情况可能同时发生在 0 个、1 个或多个分支上。这似乎不是最佳选择。

理想情况下,我想我希望能够针对 git 历史记录中的给定位置而不是整个存储库执行 git bundle verify <mybundle>。这样我就可以在将其放入磁盘之前验证它是否会失败,并且只需更改捆绑时提交的时间。除非我想做的事情有其他方法。

有什么想法吗?

您的捆绑包不应基于时间,而应基于您实际发送的内容。为此使用远程引用(未测试):

git bundle create foo.bundle --branches
git fetch foo.bundle 'refs/heads/*:refs/remotes/sent/*'
....
git bundle create foo.bundle --branches --not --remotes sent
git fetch...