在 git clone 时添加了 --depth 后,如何重新拉取所有全部的历史来获取完整的仓库

现象

由于众所周知的原因,国内在拉 https://github.com/xxx/xxx.git 的时候速度特别慢,所以呢吗,有时我们为了加快 clone 的速度会使用 --depth 参数,比如:

git clone https://github.com/xxx/xxx.git --depth 1

但是这么拉下来之后呢,会有一个问题,就是执行 git log 的时候会显示只有一条提交记录。

root@d8acdd68f269:/source_code/mesos# git log
commit 54227a33b68d83b97ef1a7c14283351d45322317 (grafted, HEAD -> master, origin/master, origin/HEAD)
Author: Andrei Sekretenko <asekretenko@apache.org>
Date:   Fri Feb 28 22:39:54 2020 +0100

    Got rid of passing Shared<> into `Subscribers::Subscriber::send(...)`.

    Now that operator API events are authorized synchronously,
    `Subscribers::Subscriber::send(...)` is no longer deferred,
    and copying arguments of `Subscribers::send()` into `Shared`
    becomes unnecessary.

    Review: https://reviews.apache.org/r/72179

那么我们要如何把之前的历史重新再 pull 下来呢?

解决方案

实际上git fetch 专门有个参数,用来将浅克隆转换为完整克隆。

root@d8acdd68f269:/source_code/mesos# git fetch --help
...
--unshallow
           Convert a shallow repository to a complete one, removing all the limitations imposed by shallow repositories.

所以,只要执行 git fetch --unshallow 就可以了,接下来就等待命令执行完成,完成后就恢复到完整克隆了。

root@d8acdd68f269:/source_code/mesos# git fetch --unshallow
remote: Enumerating objects: 152405, done.
remote: Counting objects: 100% (152405/152405), done.
remote: Compressing objects: 100% (34825/34825), done.
Receiving objects:   3% (4524/150778), 1.26 MiB | 762.00 KiB/s
  • 16
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值