如何从浅层克隆中有效地获取git [英] How to git fetch efficiently from a shallow clone

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

问题描述

我们使用 git分发操作系统并保持最新状态。由于它太大(> 2GB),我们无法分发完整的存储库,所以我们一直使用浅层克隆(〜300M)。然而,最近从浅层克隆中获取时,它现在无效地获取了整个> 2GB的存储库。这对于部署的带宽来说是无法承受的浪费。

git文档说你不能从浅仓库中获取,尽管这是不正确的。是否有任何解决方法使得 git clone --depth 1 能够从中获取更改的内容?或者有一些其他的策略来保持分发的大小尽可能小,同时让git需要做所有更新?

我没有成功尝试从 - 深度20 克隆,看看它是否会更有效地升级,这是行不通的。我也看过 http://git-scm.com/docs/git-bundle ,但似乎创建巨大的包。

解决方案

- depth 是一个 git fetch 选项。我看到这个文档没有真正强调 git clone 执行提取。

当你抓取时,这两个回收信息交换谁是从远程头开始并向后搜索fetched refs历史记录中最近的共享提交的信息,然后填充所有缺失的对象,以完成最近共享提交和新提取的提交之间的新提交。



A - 深度= 1 fetch只是获取分支提示并且没有以前的历史记录。进一步提取这些历史记录将通过上述过程获取新的内容,但是如果先前提取的提交不在新提取的历史记录中,则提取将检索所有内容 - 除非用限制提取, --depth



您的客户从一个回购仓库获取深度= 1,并将urls切换到不同的回购仓库。在这个新的回购协议中,至少有一条很长的祖先路径显然与您目前在回购协议中的任何内容不分享。这可能是值得研究的,但无论哪种方式,除非有某种特定的原因,你的客户可以做每一次抓取 - depth = 1


We use git to distribute an operating system and keep it upto date. We can't distribute the full repository since it's too large (>2GB), so we have been using shallow clones (~300M). However recently when fetching from a shallow clone, it's now inefficiently fetches the entire >2GB repository. This is an untenable waste of bandwidth for deployments.

The git documentation says you cannot fetch from a shallow repository, though that's strictly not true. Are there any workarounds to make a git clone --depth 1 able to fetch just what's changed from it? Or some other strategy to keep the distribution size as small as possible whilst having all the bits git needs to do an update?

I have unsuccessfully tried cloning from --depth 20 to see if it will upgrade more efficiently, that didn't work. I did also look into http://git-scm.com/docs/git-bundle, but that seems to create huge bundles.

解决方案

--depth is a git fetch option. I see the doc doesn't really highlight that git clone does a fetch.

When you fetch, the two repos swap info on who has what by starting from the remote's heads and searching backward for the most recent shared commit in the fetched refs' histories, then filling in all the missing objects to complete just the new commits between the most recent shared commits and the newly fetched ones.

A --depth=1 fetch just gets the branch tips and no prior history. Further fetches of those histories will fetch everything new by the above procedure, but if the previously-fetched commits aren't in the newly fetched history, fetch will retrieve all of it -- unless you limit the fetch with --depth.

Your client did a depth=1 fetch from one repo and switched urls to a different repo. At least one long ancestry path in this new repo's refs apparently shares no commits with anything currently in your repo. That might be worth investigating, but either way unless there's some particular reason, your clients can just do every fetch --depth=1.

这篇关于如何从浅层克隆中有效地获取git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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