Bundles!
git bundle 的工作流程基本上与任何其他工作流程相同。这可能看起来不是很有帮助的建议,但它是:使用您通常使用的任何工作流程,并将“推/拉”替换为“在闪存驱动器上将包从这里带到那里,然后拉”。
手册页实际上有一个非常好的演练,尽管它更多的是一个单向示例。为了完整起见,这里有一个稍微修改过的版本,展示了如何双向移动信息:
# on hostA, the initial home of the repo
hostA$ git bundle create hostA.bundle --branches --tags
# transfer the bundle to hostB, and continue:
hostB$ git clone /path/to/hostA.bundle my-repo
# you now have a clone, complete with remote branches and tags
# just to make it a little more obvious, rename the remote:
hostB$ git remote rename origin hostA
# make some commits on hostB; time to transfer back to hostA
# use the known master branch of hostA as a basis
hostB$ git bundle create hostB.bundle ^hostA/master --branches --tags
# copy the bundle back over to hostA and continue:
hostA$ git remote add hostB /path/to/hostB.bundle
# fetch all the refs from the remote (creating remote branches like hostB/master)
hostA$ git fetch hostB
# pull from hostB's master, for example
hostA$ git pull
# make some commits on hostA; time to transfer to hostB
# again, use the known master branch as a basis
hostA$ git bundle create hostA.bundle ^hostB/master --branches --tags
# copy the bundle to hostB, **replacing** the original bundle
# update all the refs
hostB$ git fetch hostA
# and so on and so on
需要注意的关键是,您可以添加捆绑包作为遥控器,并与它交互,就像与任何其他遥控器一样。要更新该遥控器,只需放入一个新的捆绑包,替换之前的捆绑包即可。
我还采取了稍微不同的方法来选择基础。手册页使用标签,始终与传输到其他主机的最新参考保持同步。我只是使用了远程分支,它将引用最后传输的引用from另一台主机。效率有点低;你最终会捆绑比你需要的更多的东西,因为它落后了一步。但闪存驱动器很大,捆绑包很小,使用已有的参考文献而不必采取额外的步骤并小心标签,可以节省大量精力。
使捆绑包变得有点麻烦的一件事是您无法推送它们,也无法“重新设置”它们。如果您希望捆绑包基于新的基础,则必须重新创建它。如果您想要其中有新的提交,则必须重新创建它。这个麻烦引起了我的下一个建议......
存储在拇指驱动器上
老实说,除非您的存储库非常大,否则这可能很简单。将裸克隆放在拇指驱动器上,您可以从两台计算机上对其进行推送和拉取。将其视为网络连接。需要转移到中央仓库吗?插上电源!