我们有两个不同的团队,每个团队都在自己的位置使用git,每个位置都有一个引用存储库。每个位置都可以访问一个企业网络,但这两个网络不能直接连接(相信我,我们问过了):我们只能交换文件。我们希望能够定期同步这两个位置,以便通过各自的参考存储库共享工作。
所需经费:
非所需:
发布于 2019-03-23 23:52:10
到目前为止,我的解决方案是使用git bundle命令,依靠远程引用来跟踪另一个位置已经有了什么,其中包括我想出的一些步骤,以便通过push/pull进行这些远程引用。让我们的位置被称为站点-a和远程位置被称为站点-b。
1. `~/work$> git clone $LOCAL_REF_URL --mirror bundler`
2. `~/work$> cd bundler`
3. `~/work/bundler$> git bundle create ../bundle-site-a-$(date +%Y-%m-%d) --branches --tags --not --remotes=site-b`bundler工作库现在可能被丢弃。
1. `~/work$> git clone -n $LOCAL_REF_URL bundle-integration`
2. `~/work$> cd bundle-integration`
3. `~/work/bundle-integration$> git checkout --detach`
4. `~/work/bundle-integration$> git fetch origin 'refs/heads/*:refs/heads/*' 'refs/remotes/site-b/*:refs/remotes/site-b/*'`
5. `~/work/bundle-integration$> git remote add site-b ../bundle-site-b`
6. `~/work/bundle-integration$> git fetch --tags site-b 'refs/heads/*'`
7. At this point the fetch told which remote site-b branches were updated with info from the bundle, so insert here the work necessary to integrate the ones that have corresponding branches in our location; first a `git fetch . 'refs/remotes/site-b/*:refs/heads/*'` to fast-forward the ones that can be in one fell swoop, then `git checkout $BRANCH && git merge site-b/$BRANCH` for the others: neither side of history can be rewritten. Also delete branches that the bundle took into account but no longer contains.
8. If `git push --tags origin 'refs/heads/*:refs/heads/*' 'refs/remotes/site-b/*:refs/remotes/site-b/*' --prune` fully succeeds, return; we are done
9. `~/work/bundle-integration$> git fetch origin` (a regular one)
10. Take into account work done on your location that happened while you were busy performing the previous steps; that still has to be done with merge (though in the more usual `git checkout $BRANCH && git merge origin/$BRANCH` idiom), except for your own merging work, which can be rebased if you prefer
11. goto 8现在,包集成工作存储库可能被丢弃。
注意:第1步不能仅仅是一个镜像克隆,因为--镜像不仅仅是假设-裸露的,它是强制的,这与以后执行集成的需要是不相容的:即使是琐碎的(快速转发) git合并操作也需要一个非空的存储库。为了将HEAD“停放”于任何分支之外,步骤3是必要的,否则,如果步骤4试图直接更新HEAD所指向的分支,则步骤4将失败。步骤4是必要的(它不获取任何提交),因为它将设置所有必要的引用,因为远程包可能不一定包含所有分支(它忽略了不提供更新的分支),而最终我们将根据自己的分支从原始分支中删除分支,因此我们希望从所有原来的分支开始;将此步骤中的规范指定为初始克隆的-c选项,而不是看起来有效。步骤5是必要的,因此git知道在步骤6中更新refs/remotes/site-b/*中的引用。
https://stackoverflow.com/questions/55319470
复制相似问题