Git:来自特定提交的浅拷贝 [英] Git: Shallow copies from a specific commit

查看:94
本文介绍了Git:来自特定提交的浅拷贝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git clone --depth N ...创建一个浅表克隆,其历史记录限于最近的N个修订版,并且我可以使用git clone -b tag ...来获取tag可以到达的提交.但是,是否有一种方法可以从特定的(带标签的)提交到分支头来获取存储库(或其分支)?

git clone --depth N ... creates a shallow clone with history limited to the last N revisions and I can use git clone -b tag ... to fetch the commits reachable from tag. However, is there a way to fetch a repository (or a branch thereof) from a specific (tagged) commit up to the branch head?

例如,我只想克隆从特定发行标签开始的历史记录.因此,如果远程中的最后几个提交看起来像这样

Say, for example, I'd like to clone only the history starting from a specific release tag. So if the last few commits in the remote look like this

[master]   ...
[master~1] ...
[master~2] ... <-- tag: x.x
[master~3] ...
...

现在,我想克隆历史记录范围x.x~1..,而不必手动计算要提供给--depth的修订数量.

Now I'd like to clone the history range x.x~1.., without having to manually count the number of revisions to give to --depth.

我想在为什么的可接受答案中给出的解释这里也没有Git克隆特定的提交选项吗?,所以可能没有直接的方法.

I guess the explanation given in the accepted answer to Why Isn't There A Git Clone Specific Commit Option? applies here as well, so there might not be a direct way.

推荐答案

实际上,没有直接的方法,这种计数或基于多引用的克隆必须在服务器端实现(服务器交付最初的浅表克隆),使其可以在git的约束下工作.

Indeed, there is no direct way, and this kind of counting or multiple-ref-based cloning would have to be implemented on the server side (the server delivering the initial shallow clone) for it to work within git's constraints.

不过有一种间接方法:从深度为1的浅克隆开始,然后反复加深直到标签出现.令人讨厌的是,git fetch --depth=<N>不会选择新标签(但是您可以使用git ls-remote或类似标签在浅克隆客户端上获取所有内容一次,并注意SHA-1).但是我怀疑这种方法太慢了,以至于变得毫无价值.

There's an indirect way though: start with a depth 1 shallow clone, then deepen repeatedly until the tag appears. Annoyingly, git fetch --depth=<N> won't pick up new tags (but you can use git ls-remote or similar to get everything once on the shallow-clone client, and watch for the SHA-1). But I suspect this method would be so slow as to make it pretty worthless.

这篇关于Git:来自特定提交的浅拷贝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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