我需要在不同的计算机上保持我的开发树同步,它们之间没有网络连接.
我们有一个中央git存储库,我通常在办公室计算机上使用自己的克隆.有时我需要在另一台从未连接到办公室网络的计算机上进行一些开发.没有任何计算机连接到Internet.可以在同步之间在两台计算机上执行开发.
我已经阅读了git-bundle的帮助页面,这似乎是最好的工具,但我不确定如何设置好的工作流程.
你能给我一些建议或指点吗?
Cas*_*bel 110
使用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
Run Code Online (Sandbox Code Playgroud)
需要注意的关键是,您可以将捆绑包添加为远程,并与其他任何远程协议进行交互.要更新该远程,只需放入一个新的捆绑包,替换之前的捆绑包.
我采取了一种略微不同的方法来选择基础.手册页使用标签,始终与最后一个转移到其他主机的引用保持同步.我只是使用了远程分支,它将引用从其他主机传输的最后一个引用.这有点低效; 你最终会捆绑超过你需要的东西,因为它落后了一步.但闪存驱动器很大,捆绑包很小,并且使用你已经拥有的refs而不必采取额外的步骤并且小心标签可以节省很多精力.
使捆绑有点麻烦的一件事是你无法推动它们,你不能"重新"它们.如果您希望基于新基础的捆绑包,则必须重新创建它.如果你想要新的提交,你必须重新创建它.这个麻烦引起了我的下一个建议......
老实说,除非您的回购非常大,否则这可能同样容易.将裸克隆放在拇指驱动器上,您可以从两台计算机上推送和拉出它.像对待网络一样对待它.需要转移到中央回购?插上电源!
@Jefromi的答案很棒 - 比git docs好10倍,后者详细讲述了难以理解的要求和行为.
它仍然有点复杂,所以这里是最简单的情况同步一次(在我的情况下:FROM:一台带有破损wifi卡的离线笔记本电脑,TO:一台带网络访问权限的桌面).根据@ Jefromi的回答,这似乎工作得很好:
AHEAD =通过一些提交提前的机器.BEHIND =要将提交复制到的计算机
1. AHEAD: git-bundle create myBundleName.bundle --branches --tags
Run Code Online (Sandbox Code Playgroud)
BOTH:复制myBundleName.bundle(使用电子邮件,USB,等等)
后悔:(将文件myBundName.bundle放在项目文件夹之外的任何地方)
2. BEHIND: cd [the project folder]
3. BEHIND: git pull [path to the bundle file]/myBundleName.bundle master
Run Code Online (Sandbox Code Playgroud)
只要你在末尾包含branch-name(默认情况下,如果你没有使用分支,"master"),这似乎工作正常,并且不会替换BEHIND上的任何内部引用 - 所以你仍然可以与原始主人同步.
即如果BEHIND有互联网接入,它仍然是安全的:
(OPTIONAL) 4. BEHIND: git push
Run Code Online (Sandbox Code Playgroud)
...它将更新主存储库,就好像您的更改已在BEHIND上本地完成一样.