如何使用git-bundle保持开发同步? [英] How to use git-bundle for keeping development in sync?

查看:219
本文介绍了如何使用git-bundle保持开发同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们有一个中央git存储库,而且我通常都在工作我自己的办公室电脑上的克隆。有时我需要在另一台未连接到办公网络的计算机上进行一些开发。没有一台电脑连接到互联网。开发可能会在两台计算机之间进行同步。



我已阅读 git-bundle ,这似乎是最好的工具,但我不确定如何建立一个好的工作流程。



您可以给我一些建议或指针吗?

解决方案



使用git bundle的工作流程将与其他任何工作流程基本相同。这似乎不是非常有帮助的建议,但是这里是:使用任何你通常使用的工作流程,并且用在这里将一个包装带到闪存驱动器上,然后拉动替换推/拉。



手册页实际上有一个相当不错的演练,尽管它更像是一个单向的例子。为了完整起见,这里有一个稍微修改过的版本,展示了如何移动信息:


hostA $ git bundle创建hostA.bundle --branches --tags

#将包转移到hostB,然后继续:
hostB $ git clone /path/to/hostA.bundle my-repo
#你现在拥有一个克隆,并带有远程分支和标签
#,以使其更加明显,重命名远程:
hostB $ git remote rename origin hostA

#在hostB上进行一些提交;时间转移回hostA
#使用hostA的已知主分支作为基础
hostB $ git包创建hostB.bundle ^ hostA / master --branches --tags

#将包复制回hostA并继续:
hostA $ git remote add hostB /path/to/hostB.bundle
#从远程获取所有的引用(创建远程分支,如hostB / master )
hostA $ git fetch hostB
从hostB的主服务器上拉,例如
hostA $ git pull

#在hostA上进行一些提交;时间再次转移到hostB
#,使用已知的主分支作为基础
hostA $ git包创建hostA.bundle ^ hostB / master --branches --tags
#复制包到hostB,**替换**原始包
#更新所有的引用
hostB $ git fetch hostA

#等等等等

关键要注意的是,您可以将一个包添加为一个远程,并与其进行交互,就像使用其他任何其他远程。要更新该远程设备,只需放入一个新的软件包,替换之前的软件包即可。

我也采取了一种稍微不同的方法来选择基础。手册页使用标签,始终保持与最后一次转交给其他主机的参考文献保持一致。我简单地使用了远程分支,它将引用从从其他主机传输的最后一个参考。这有点低效;你将最终捆绑超过你的需要,因为它落后了一步。但闪存驱动器很大,捆绑包很小,并且使用已有的参考代码,而不必采取额外措施,小心标签可以节省大量工作。



让捆绑有点麻烦的一件事是,你不能推动他们,你不能改变他们。如果您想要基于新基础的软件包,则必须重新创建它。如果你想要新的提交,你必须重新创建它。这个麻烦引起了我的下一个建议......



在硬盘上回购



老实说,除非你回购确实很大,这可能同样简单。将一个裸露的克隆放在拇指驱动器上,然后您可以从两台计算机上推入并从中拉出。像你的网络连接一样对待它。需要转移到中央回购?插入!


I need to keep my development trees in sync on different computers, with no network connection between them.

We have a central git repository, and I normally work on my own clone on my office computer. Sometimes I need to do some development on another computer, which is never connected to the office network. None of the computers are ever connected to Internet. Development may be performed on both computers between synchronizations.

I have read the help pages for git-bundle, which seems like the best tool, but I am not really sure how a good workflow could be set up.

Can you give me some advice or pointers?

解决方案

Bundles!

The workflow with git bundle is going to be essentially the same as any other workflow. This may not seem like terribly helpful advice, but here it is: use whatever workflow you would normally use, and replace "push/pull" with "carry a bundle here to there on a flash drive, then pull".

The man page actually has a pretty good walkthrough for getting going with this, although it's more of a one-way example. For the sake of completeness, here's a slightly modified version of it, showing how to move information both ways:

# 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

The key thing to notice is that you can add a bundle as a remote, and interact with it just as you would with any other remote. To update that remote, just drop in a new bundle, replacing the previous one.

I've also taken a slightly different approach to picking a basis. The man page uses tags, always kept up to date with the last refs which were transferred to the other host. I've simply used the remote branches, which will refer to the last refs transferred from the other host. It's a little bit inefficient; you'll end up bundling more than you need to, since it's one step behind. But flash drives are big, bundles are small, and using the refs you already have instead of having to take an extra step and be careful about tags saves a lot of effort.

The one thing that makes bundles a bit of trouble is that you can't push to them, and you can't "rebase" them. If you want the bundle based on a new basis, you have to recreate it. If you want new commits in it, you have to recreate it. This hassle gives rise to my next suggestion...

Repo on a thumb drive

Honestly, unless your repo is really big, this might be just as easy. Put a bare clone on a thumb drive, and you can push to and pull from it from both computers. Treat it like your network connection. Need to transfer to the central repo? Plug it in!

这篇关于如何使用git-bundle保持开发同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆