如何在不可靠的连接上克隆大型 Git 存储库?
我想克隆 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
# slowerTarballs:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
可以通过此处的
http
协议(又名哑协议)访问存储库:http://anongit.freedesktop.org/git/libreoffice/core.git。您可以使用
wget
或其他下载管理器下载此处的所有内容,并且您将获得存储库的克隆。之后,将目录从core.git
重命名为.git
,并使用以下命令告诉 git 有关远程 url 的信息: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 fromcore.git
to.git
, and use the following command to tell git about the remote url:增加缓冲区大小,以便 git 可以正确利用您的带宽。使用以下命令。
等待克隆完成。
Increase buffer size so that git can utilize your bandwidth properly. Use following commands.
Wait till clone get complete.
您可以执行以下操作:
第一个克隆仍然是原子的,因此如果您的连接不够可靠,无法获取当前的 HEAD,那么您就会遇到麻烦。
如果连接中途断开,后续的
fetch
应该是增量的并且可以重试。You can do the following:
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.执行“git clone --深度 100”
它应该抓取最后 100 次提交
do 'git clone --depth 100'
It should grab the last 100 commits
据我所知,最好的方法是结合 浅克隆 (
--深度 1
) 具有 稀疏功能checkout,即仅检出您需要的子文件夹或文件。 (浅克隆也意味着--single-branch
,这也很有用。)请参阅 udondan 的回答 举个例子。此外,我使用 bash 循环不断重试,直到成功完成。像这样:
通过这种方式,即使在中国使用速度较慢的 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:
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.
我使用具有 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.
我的连接速度很慢。对我有用的方法是在服务器上克隆。就我而言,我的文件可以在 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.