我试图git克隆LibreOffice代码库,但目前我有一个大约300kbps的互联网连接,它只是什么都不稳定。我可以在任何时候恢复连接,但是git克隆进程已经停止工作,没有办法让它再次运行。有没有什么方法可以让git克隆下载更具抗失败性?

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


当前回答

我想到的两种解决方案(或者说是变通方法)是:

Use shallow clone i.e. git clone --depth=1, then deepen this 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 bundle up 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.

其他回答

让我们把git克隆分解成它的组成部分,并使用git签出来防止重新下载文件。

当git克隆运行时,它所做的前几件事等同于

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

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

git checkout --force <branch>

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

我觉得这个还没准备好。有一个旧的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


更新

除了浅克隆(git clone——depth=1)的建议外,如果有人可以为您创建一个裸库(如果您可以与提供者沟通),这可能会有所帮助。您可以轻松地将裸存储库转换为完整存储库。另外,请阅读答案中的评论,因为肤浅的克隆可能并不总是有帮助。

该方法使用第三方服务器。

首先,做 Git克隆——裸的,然后 rsync -v -P -e ssh user@host:repo。git。 Windows下可以使用msys。

你可以“下载其他人的.git目录”,但是这个其他人就是官方的存储库本身。LibreOffice存储库可以通过http获取,例如它们的构建。git在http://anongit.freedesktop.org/git/libreoffice/build.git/(完整列表见http://cgit.freedesktop.org/libreoffice/, http URL在每个存储库页面的底部)。

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

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

这个问题也困扰着我。对我来说,有一个变通办法。它可能适用于你,也可能不适用。

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