简体   繁体   English

如何克隆git repo片段

[英]How to clone a git repo piecemeal

I'm cloning the Linux kernel repository. 我正在克隆Linux内核存储库。 The repository is so huge and my network is so slow that I can't clone it all at once. 该存储库是如此之大,我的网络是如此之慢,以至于我无法一次全部克隆它。 That may keep my computer on for a whole week. 这可能会使我的计算机保持整整一周的时间。

If I stop the cloning mid-operation, progress would be lost. 如果我停止克隆操作,将失去进度。 How can I partially clone a git repository? 如何部分克隆git存储库?

Cloning cannot be resumed, if it's interrupted you'd need to start over. 无法恢复克隆,如果中断,则需要重新开始。 There can be a couple of workaround though: 但是,可以有两种解决方法:

You can use shallow clone ie git clone --depth=1 , then you can deepen this repository using git fetch --depth=N , with increasing N. But disclaimer is, I have never tried myself. 您可以使用浅层克隆,即git clone --depth=1 ,然后可以使用git fetch --depth=N来加深此存储库,并增加N。但是免责声明是,我从未尝试过自己。

Another option could be git-bundle . 另一个选择可以是git-bundle The bundle itself is a single file, which you can download via HTTP or FTP with resume support (via BitTorrent, rsync or using any download manager). 捆绑包本身是一个文件,您可以通过具有恢复支持的HTTP或FTP下载(通过BitTorrent,rsync或使用任何下载管理器)。 You can have somebody to create a bundle for you and then download it and create a clone from that. 您可以让某人为您创建捆绑包,然后下载它并从中创建一个克隆。 Correct the configuration and next of fetch from the original repo. 更正配置,然后从原始存储库中提取。

I'm not sure what you mean by separately but git clone is going to clone the whole repo as there is no way to clone just some part of a repo. 我不确定您分别表示什么,但是git clone将克隆整个仓库,因为无法克隆仓库的一部分。

But you can do a shallow clone with just a depth of one commit and/or only one branch 但是您可以只进行一次提交和/或只进行一个分支的深度即可进行浅表克隆

git clone --depth=1 --single-branch --branch master

That will just grab the last commit of the master branch. 那将只是获取master分支的最后一次提交。

git clone --depth 100 will only grab the last 100 commits. git clone --depth 100将仅捕获最近的100次提交。

In general it looks like what you actually want is unsupported: 通常,您实际想要的东西似乎不受支持:

All kind of say "this doesn't exist yet." 各种各样的说法“这还不存在”。

But some large repos also host "dumb" http ways to retrieve the repo ( not git-layer clone) to solve this problem. 但是一些大型存储库还使用“哑” http方法来检索存储库( 不是 git层克隆)来解决此问题。 Linux kernel may. Linux内核可能。

A clone is actually a series of smaller steps. 克隆实际上是一系列较小的步骤。 In a nutshell, it first downloads a list of references, then it retrieves the pack file or loose object file for each of those references. 简而言之,它首先下载引用列表,然后为每个引用检索打包文件或松散的目标文件。 There's currently no way to resume an interrupted clone automatically, because a clone usually sends one big pack file, but with some work and research you should be able to request smaller packs manually, the same as someone who does a series of pulls over time. 当前无法自动恢复被中断的克隆,因为克隆通常会发送一个大文件包文件,但是通过一些工作和研究,您应该能够手动请求较小的文件包,就像随时间推移进行一系列提取的人一样。

Look at the git book chapter on transfer protocols and the git fetch-pack command for more information. 参阅有关传输协议的git书籍章节git fetch-pack命令以获取更多信息。 Also, git's source code is available on github , so you may be able to add a resume option yourself, or at least use it to get an idea of how clones are done internally. 此外,git的源代码可在github上找到 ,因此您可以自己添加履历选项,或至少使用它来了解如何在内部完成克隆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM