How to maintain shallow clone of a set of branches in git

[亡魂溺海] 提交于 2019-12-23 16:24:51

问题


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?


回答1:


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".



来源:https://stackoverflow.com/questions/28645657/how-to-maintain-shallow-clone-of-a-set-of-branches-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!