如何在不稳定的连接上完成一个大项目的 git clone?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3954852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:18:06  来源:igfitidea点击:

How to complete a git clone for a big project on an unstable connection?

gitgit-clone

提问by LaPingvino

I am trying to git clone the LibreOffice codebase, but at the moment I have an internet connection of about 300kbps and it's just anything but stable. I can get the connection back any moment, but then the git clone process already stopped working, and no way to get it running again. Is there some way to have a more failure-resistant git clone download?

我正在尝试 git clone LibreOffice 代码库,但目前我有大约 300kbps 的互联网连接,但它一点也不稳定。我可以随时恢复连接,但是 git clone 进程已经停止工作,并且无法再次运行。有没有办法让 git clone 下载更加抗故障?

One option I considered myself is to download someone else's .git directory, but that is overly dependent of others and doesn't seem like the best possible solution to me.

我自己考虑的一种选择是下载其他人的 .git 目录,但这过于依赖其他人,对我来说似乎不是最好的解决方案。

采纳答案by Jungle Hunter

I don't think this is ready yet. There's an old GSoC pagethat which planned to implement your desired feature. My best bet is, like you suggested download it as a directory. I'm assuming you are able to resume downloads over other protocols.

我认为这还没有准备好。有一个旧的 GSoC 页面计划实现您想要的功能。我最好的选择是,就像您建议将其下载为目录一样。我假设您能够通过其他协议恢复下载。

Restartable Clone

When cloning a large repository (such as KDE, Open Office, Linux kernel) there is currently no way to restart an interrupted clone. It may take considerable time for a user on the end of a small pipe to download the data, and if the clone is interrupted in the middle the user currently needs to start over from the beginning and try again. For some users this may make it impossible to clone a large repository.

Goal: Allow git-clone to automatically resume a previously failed download over the native git:// protocol. Language: C Mentor: Shawn Pearce Suggested by: Shawn Pearce on gmane

可重启克隆

克隆大型存储库(例如 KDE、Open Office、Linux 内核)时,目前无法重新启动中断的克隆。小管道末端的用户下载数据可能需要相当长的时间,如果克隆在中间中断,用户当前需要从头开始并重试。对于某些用户来说,这可能导致无法克隆大型存储库。

目标:允许 git-clone 通过本机 git:// 协议自动恢复以前失败的下载。语言:C 导师:Shawn Pearce 建议人:Shawn Pearce on gmane



Update

更新

Along with the shallow cloning (git clone --depth=1) suggestion in one of the other answers it may be helpful if someone can make a bare repository for you if you can communicate with the provider. You can easily convertthe bare repository to a full repository. Also read the comments in that answer as a shallow clone may not always help.

git clone --depth=1其他答案之一中的浅克隆 ( ) 建议一起,如果您可以与提供者进行交流,那么如果有人可以为您创建一个裸存储库,这可能会有所帮助。您可以轻松地裸存储库转换为完整存储库。另请阅读该答案中的评论,因为浅层克隆可能并不总是有帮助。

回答by Jakub Nar?bski

Two solutions (or rather workarounds) that come to mind are:

想到的两个解决方案(或者更确切地说是解决方法)是:

  • Use shallow clonei.e. git clone --depth=1, then deepenthis clone using git fetch --depth=N, with increasing N. You can use git fetch --unshallow(since 1.8.0.3) to download all remaining revisions.

  • Ask somebody to bundleup to some tagged release (see git-bundle(1)manpage). The bundle itself is an ordinary file, which you can download any way, via HTTP/FTP with resume support, via BitTorrent, via rsync, etc. The you can create clone from bundle, fix configuration, and do further fetches from official LibreOffice repository.

  • 使用浅克隆ie git clone --depth=1,然后使用加深这个克隆git fetch --depth=N,随着N 的增加。您可以使用git fetch --unshallow(自 1.8.0.3 起)下载所有剩余的修订版。

  • 要求某人捆绑一些标记的版本(请参阅git-bundle(1)联机帮助页)。捆绑包本身是一个普通文件,您可以通过任何方式下载它,通过支持恢复的 HTTP/FTP,通过 BitTorrent,通过 rsync 等。您可以从捆绑包创建克隆,修复配置,并从官方 LibreOffice 存储库中进一步获取.

回答by Rafal Rusin

This method uses 3rd party server.

此方法使用第 3 方服务器。

First, do git clone --bare, then rsync -v -P -e ssh user@host:repo.git .You can use msys under Windows.

先做 git clone --bare,然后 rsync -v -P -e ssh user@host:repo.git .Windows下就可以使用msys了。

回答by jthill

"Never underestimate the bandwidth of a carrier pigeon and a bundle of SD cards" would be the modern form of this answer. Tar it up, plain old cp -ait, whatever, and mail the damn thing. Find someone willing to take two minutes of their time to drop a thumb drive into an SASE. Find a contact, there, they might even do it for you.

永远不要低估一只信鸽和一捆 SD 卡的带宽”将是这个答案的现代形式。把它涂上焦油,老cp -a样子,随便,然后邮寄这该死的东西。找一个愿意花两分钟时间将 U 盘放入 SASE 的人。找到一个联系人,在那里,他们甚至可能为你做。

回答by CesarB

You can "download someone else's .git directory", but with that someone else being the official repository itself. The LibreOffice repositories are available via http, for instance their build.gitis at http://anongit.freedesktop.org/git/libreoffice/build.git/(see http://cgit.freedesktop.org/libreoffice/for the complete list, the http URL is at the bottom of each repository's page).

您可以“下载其他人的 .git 目录”,但其他人本身就是官方存储库。LibreOffice 存储库可通过 http 获得,例如它们build.git位于http://anongit.freedesktop.org/git/libreoffice/build.git/(有关完整列表,请参阅http://cgit.freedesktop.org/libreoffice/, http URL 位于每个存储库页面的底部)。

What you see at these http URLs is nothing more than a .gitdirectory (actually a "bare" repository, which has only what you would find in the .gitdirectory). It is the same directory the server for the git://protocol (git daemon) would read. If you make a copy of these directories with a web downloader (for instance wget -m -np), you can clone from your copy and it will work as well as if you had cloned directly from the http repository.

您在这些 http URL 上看到的只不过是一个.git目录(实际上是一个“裸”存储库,其中只有您可以在.git目录中找到的内容)。它与git://协议 ( git daemon)的服务器将读取的目录相同。如果您使用 Web 下载器制作这些目录的副本(例如wget -m -np),您可以从您的副本进行克隆,它会像直接从 http 存储库克隆一样工作。

So, what you can do is: for each repository, get a copy of it with your favorite web downloader (which will deal with all the issues with resuming broken downloads), and clone from that copy. When you want to update, use again your favorite web downloader to update your copy, and pull from that copy. Now your clones and updates are as resistant to bad connections as your favorite web downloader is.

因此,您可以做的是:对于每个存储库,使用您最喜欢的 Web 下载器获取它的副本(它将处理恢复损坏下载的所有问题),然后从该副本进行克隆。当您想要更新时,再次使用您最喜欢的网络下载器来更新您的副本,然后从该副本中提取。现在,您的克隆和更新可以像您最喜欢的网络下载器一样抵抗不良连接。

回答by cowlinator

Let's break git clonedown into it's component parts, and use git checkoutto prevent re-downloading files.

让我们分解git clone成它的组成部分,并用于git checkout防止重新下载文件。

When git cloneruns, the first few things it does are equivalent to

git clone运行时,它做的第一件几件事情相当于

git init
git remote add origin <repo_url>
git fetch origin <branch>

If you run the above steps manually, and assuming that they completed correctly, you can now run the following as many times as necessary:

如果您手动运行上述步骤,并假设它们正确完成,您现在可以根据需要多次运行以下步骤:

git checkout --force <branch>

Note that it will checkout all files each time it's run, but you will not have to re-download files, which may save you a ton of time.

请注意,它每次运行时都会检出所有文件,但您不必重新下载文件,这可能会为您节省大量时间。

回答by Ahed Eid

git clone --depth <Number> <repository> --branch <branch name> --single-branch

This command help me (Thanks to Nicola Paolucci)

这个命令帮助我(感谢Nicola Paolucci

for example

例如

git clone --depth 1 https://github.com/gokhanmoral/siyahkernel3 --branch ics  --single-branch

回答by Amber

If you have access to a 3rd-party server, you could clone there and then copy.

如果您有权访问第 3 方服务器,则可以在那里克隆然后复制。

回答by Tony Sidaway

This problem bit me too. In my case there is a work-around. It may or may not apply in your case.

这个问题也困扰着我。就我而言,有一个解决方法。它可能适用于您的情况,也可能不适用。

I'm using a mobile phone sometimes to initiate git operations on a remote system. If my wi-fi breaks of course the session ends and git drops the whole clone operation without recovering. But since the internet connection from my remote system to the git master is solid there's no need for the clone to stop. All I need is the commonsense to detach the clone from the terminal session. This can be done by using screen/tmux or nohup/daemon. So it's a liveware malfunction in my case.

我有时会使用手机在远程系统上启动 git 操作。如果我的 wi-fi 中断当然会话结束并且 git 删除整个克隆操作而不恢复。但是由于从我的远程系统到 git master 的互联网连接是可靠的,因此不需要停止克隆。我所需要的只是将克隆与终端会话分离的常识。这可以通过使用 screen/tmux 或 nohup/daemon 来完成。所以在我的情况下这是一个活件故障。

回答by Stephen

Building on the clone/depth based answers - a few lines of bash gets this done easily...

以基于克隆/深度的答案为基础 - 几行 bash 就可以轻松完成...

git clone --depth=1 [email protected]:/var/git/whatever.git <directory> cd <directory> for m in `seq 1 100`;do git fetch --depth=$m;done

git clone --depth=1 [email protected]:/var/git/whatever.git <directory> cd <directory> for m in `seq 1 100`;do git fetch --depth=$m;done