如何在git中维护一组分支的浅层克隆 [英] How to maintain shallow clone of a set of branches in git

查看:110
本文介绍了如何在git中维护一组分支的浅层克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保留几个分支的简单,镜像,纯粹的克隆。我将从本地克隆不同的项目分支。例如

  + ------------------------ ------------------------------------------ + 
| repo1:server1:original-repo.git分支:A,B,C,D,E |
+ --------------------------------------------- --------------------- +

+ ------------------ ------------------------------------------------ +
| repo2:server2:浅 - 裸选择性克隆分支:A,B only |
+ --------------------------------------------- --------------------- +
↓↓
+ ----------------- -------------- + + -------------------------------- +
| repo3:server2:克隆repo2,A | | repo4:server2:克隆repo2,B |
+ ------------------------------- + + ------------ -------------------- +

所以,我可以让repo2这样

  git的克隆--bare --mirror --depth 1服务器1:repo1 repo2 
cd repo2
git fetch --depth 200 origin A
git fetch --depth 200 origin B

然后我认为repo3和4真的很容易 - 他们可以从repo2克隆所有他们想要的东西,它们将受到repo2浅薄度的限制。



但是保持repo1与repo1的最新版本,同时保持其浅度是我坚持的(理想情况下,我想保持一切,因为某个提交,但我明白这是不可能的)。看来我必须每次都执行多个git fetch命令,对吗?有没有办法在配置文件中弹出,以便我可以执行 git fetch 并且它知道我的意思?

在寻找类似的复杂Git需求时,我遇到了这个问题,并且完全理解这个问题是2岁。我正在回答,因为根本没有答案,而问题仍然非常有效。 浅浅主要是 fetch 属性。因此,可以使用 - 深度200 来执行获取,并保留历史记录,而不会提交过时的提交。



现代版本的Git有 - shallow-exclude 选项。我认为这正是允许自从某个提交以来维护所有内容的原因。


I'd like to maintain a shallow, mirrored, bare clone of several branches. I will clone locally from that for different project branches. e.g.

+------------------------------------------------------------------+
| repo1: server1:original-repo.git branches: A, B, C, D, E         |
+------------------------------------------------------------------+
  ↓
+------------------------------------------------------------------+
| repo2: server2:shallow-bare-selective-clone branches: A, B only  |
+------------------------------------------------------------------+
  ↓                                 ↓
+-------------------------------+ +--------------------------------+
| repo3: server2:clone repo2, A | | repo4: server2:clone repo2, B  |
+-------------------------------+ +--------------------------------+

So I can make repo2 like this

git clone --bare --mirror --depth 1 server1:repo1  repo2
cd repo2
git fetch --depth 200 origin A
git fetch --depth 200 origin B

And then I think repo3 and 4 are really easy - they can clone all they want from repo2, they will be limited by the shallowness of repo2.

But keeping repo2 up to date from repo1 while maintaining its shallowness is what I'm stuck on (ideally I'd like to maintain everything since a certain commit, but I understand that's not possible). It seems I have to do the multiple git fetch commands each time, is this right? Is there a way to pop that in the config file so that I can just do git fetch and it knows what I mean?

解决方案

I faced this question when searching for analogous sophisticated Git needs and perfectly understand that question is 2 years old. I'm answering because there are no answers at all whereas question is still very valid.

Shallowness is primarily fetch property. So it's possible to do fetch with --depth 200 and maintain history without too old commits.

Modern versions of Git have --shallow-exclude option. I think it's exactly what allows to "maintain everything since a certain commit".

这篇关于如何在git中维护一组分支的浅层克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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