如何在不可靠的连接上克隆大型 Git 存储库?

发布于 2025-01-05 04:14:11 字数 554 浏览 1 评论 0原文

我想克隆 LibreOffice。从官方网站上看,是这样写的:

我们所有的源代码都托管在 git 中:

克隆:$ git clone git://anongit.freedesktop.org/libreoffice/core #(浏览)

克隆 (http): $ git clone http://anongit.freedesktop.org/git/libreoffice/core.git # 较慢

压缩包:http://download.documentfoundation.org/libreoffice/src/

请查找最新版本(通常位于底部附近)

现在,当我在 git bash 中编写此命令进行克隆时,它开始获取。但存储库太大了,几个小时后我失去连接几秒钟,它回滚下载,我什么也得不到。

有什么办法即使出现中断也可以顺利下载存储库吗?

PS 我是 Git 的新用户,我使用 1 MB DSL 互联网连接。存储库必须超过 1 GB。

I want to clone LibreOffice. From the official website, this is what's written:

All our source code is hosted in git:

Clone: $ git clone git://anongit.freedesktop.org/libreoffice/core # (browse)

Clone (http): $ git clone http://anongit.freedesktop.org/git/libreoffice/core.git # slower

Tarballs: http://download.documentfoundation.org/libreoffice/src/

please find the latest versions (usually near the bottom)

now, when I write this command in git bash to clone, it starts fetching. But the repository is so big that after hours I lose connectivity for a few seconds, it rolls back the download, and I get nothing.

Is there any way I can download the repository smoothly even if interruptions occur?

P.S. I am a new user of Git and I use a 1 MB DSL internet connection. The repository must be over 1 GB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

你是暖光i 2025-01-12 04:14:11

可以通过此处的 http 协议(又名哑协议)访问存储库:http://anongit.freedesktop.org/git/libreoffice/core.git

您可以使用 wget 或其他下载管理器下载此处的所有内容,并且您将获得存储库的克隆。之后,将目录从 core.git 重命名为 .git,并使用以下命令告诉 git 有关远程 url 的信息:

$ git remote add remote http://anongit.freedesktop.org/git/libreoffice/core.git
$ git reset --hard HEAD

The repository is accessible via the http protocol (aka dumb protocol) here: http://anongit.freedesktop.org/git/libreoffice/core.git.

You can download everything here with wget or another download manager, and you'll have a clone of the repository. After that, you rename the directory from core.git to .git, and use the following command to tell git about the remote url:

$ git remote add remote http://anongit.freedesktop.org/git/libreoffice/core.git
$ git reset --hard HEAD
任谁 2025-01-12 04:14:11

增加缓冲区大小,以便 git 可以正确利用您的带宽。使用以下命令。

git config --global core.compression 0

git config --global http.postBuffer 1048576000

git config --global http.maxRequestBuffer 100M

git clone <repo url>

等待克隆完成。

Increase buffer size so that git can utilize your bandwidth properly. Use following commands.

git config --global core.compression 0

git config --global http.postBuffer 1048576000

git config --global http.maxRequestBuffer 100M

git clone <repo url>

Wait till clone get complete.

写下不归期 2025-01-12 04:14:11

您可以执行以下操作:

git clone --depth 1 [email protected]:User/Project.git .
git fetch --unshallow

第一个克隆仍然是原子的,因此如果您的连接不够可靠,无法获取当前的 HEAD,那么您就会遇到麻烦。

如果连接中途断开,后续的fetch应该是增量的并且可以重试。

You can do the following:

git clone --depth 1 [email protected]:User/Project.git .
git fetch --unshallow

The first clone will still be atomic, so if your connection is not reliable enough to fetch the current HEAD then you will have trouble.

The subsequent fetch should be incremental and retryable if the connection drops half-way though.

孤蝉 2025-01-12 04:14:11

执行“git clone --深度 100”
它应该抓取最后 100 次提交

do 'git clone --depth 100'
It should grab the last 100 commits

安穩 2025-01-12 04:14:11

据我所知,最好的方法是结合 浅克隆 (--深度 1) 具有 稀疏功能checkout,即仅检出您需要的子文件夹或文件。 (浅克隆也意味着 --single-branch,这也很有用。)请参阅 udondan 的回答 举个例子。

此外,我使用 bash 循环不断重试,直到成功完成。像这样:

#!/bin/bash

git init <repo_dir>
cd <repo_dir>
git remote add origin <repo_url>

# Optional step: sparse checkout
git config core.sparsecheckout true                     # <-- enable sparse checkout
echo "subdirectory/*" >> .git/info/sparse-checkout      # <-- specify files you need

# Keep pulling until successful
until $( git pull --depth=1 origin master ); do         # <-- shallow clone
    echo "Pulling git repository failed; retrying..."
done

通过这种方式,即使在中国使用速度较慢的 VPN,我最终也可以拉取大型存储库……

重要的是,通过这种方式拉取,您仍然能够推送。

The best method that I know of is to combine shallow clone (--depth 1) feature with sparse checkout, that is checking out only the subfolders or files that you need. (Shallow cloning also implies --single-branch, which is also useful.) See udondan's answer for an example.

Additionally, I use a bash loop to keep retrying until finished successfully. Like this:

#!/bin/bash

git init <repo_dir>
cd <repo_dir>
git remote add origin <repo_url>

# Optional step: sparse checkout
git config core.sparsecheckout true                     # <-- enable sparse checkout
echo "subdirectory/*" >> .git/info/sparse-checkout      # <-- specify files you need

# Keep pulling until successful
until $( git pull --depth=1 origin master ); do         # <-- shallow clone
    echo "Pulling git repository failed; retrying..."
done

In this way I can eventually pull large repos even with slow VPN in China…

Importantly, by pulling this way you will still be able to push.

梦里的微风 2025-01-12 04:14:11

我使用具有 shell 访问权限的网络托管服务器首先克隆它,然后使用 rsync 将其复制到本地。 rsync 恢复时将仅复制剩余文件。

I used a my web hosting server with shell access to clone it first and then used rsync to copy it locally. rsync would copy only remaining files when resumed.

烛影斜 2025-01-12 04:14:11

我的连接速度很慢。对我有用的方法是在服务器上克隆。就我而言,我的文件可以在 PythonAnywhere 上克隆。然后我压缩该目录并通过 XDM 下载它。但我不确定我是否具有推送功能。

I have a very slow connection. The method that worked for me is cloning on a server. In my case, my files could be cloned on PythonAnywhere. I then zipped the directory and downloaded it via XDM. I'm not sure I'll have push capabilities though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文