仓库太大,clone 后,git pull 老分支成功,最新分支失败

由于 git 仓库太大,新加入的小伙伴在拉取时,无法切换到最新的分支,报错如下:

复制代码
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

在此记录解决步骤,

1、clone

复制代码
git clone --depath 1 xxx.git

2、切换分支

由于未 clone 整个仓库,也就拉不到所有分支,自然无法通过 checkout 切换分支。

在此通过手工处理:

1、打开根目录下的隐藏文件:.git/config
2、改动文件:

js 复制代码
[remote "origin"]
	url = https://git.code.tencent.com/pokergaga/PokerGagaClient.git
    // fetch = +refs/heads/master:refs/remotes/origin/master  将这行改为分支:3.2.0
	fetch = +refs/heads/3.2.0:refs/remotes/origin/3.2.0

3、奇怪的报错

如上改了配置文件后,一般执行如下代码即可:

bash 复制代码
git pull
git checkout 3.2.0 #目标分支

以前在这一步都很顺利,但这一次居然不行,在 git pull 时报同样的错。

然后在手工换到上一个版本 3.1.0 再试,嘿,居然成功了!

再尝试将 3.1.0 历史全部下载:

bash 复制代码
git fetch --unshallow

可惜还是报同样的错。

4、解决

经过网上多番查着,未发现有遇到过此问题的文章。

再仔细查看了 fetch 命令:

bash 复制代码
git fetch -h
    # ...
	# -k, --keep            keep downloaded pack
	# --unshallow           convert to a complete repository

再次尝试:

bash 复制代码
git fetch --unshallow -k -v

下载成功!

再如上步骤2、3 所示,手工切换到 3.2.0,成功!

相关推荐
蓝色空白的博客1 小时前
Git代码下拉更新推送操作用法整理
git
风也温柔☆3 小时前
IDEA/WebStorm 切换分支(超简单)
git·intellij-idea·webstorm·切换分支·checkout
Jammingpro14 小时前
【Git版本控制】Git初识、安装、仓库初始化与仓库配置(含git init、git config与配置无法取消问题)
java·git·elasticsearch
shark21 小时前
无需放弃变更、关闭占用程序!用暂存区和 git底层命令实现 Git 变更备份
git·shell·自动化运维
_poplar_21 小时前
15 【C++11 新特性】统一的列表初始化和变量类型推导
开发语言·数据结构·c++·git·算法
北城笑笑21 小时前
Git 10 ,使用 SSH 提升 Git 操作速度实践指南( Git 拉取推送响应慢 )
前端·git·ssh
蓁蓁啊1 天前
GIT使用SSH 多账户配置
运维·git·ssh
相与还1 天前
IDEA和GIT实现cherry pick拣选部分变更到新分支
git·elasticsearch·intellij-idea
刘志辉2 天前
git指令
git
2501_916766542 天前
【Git学习】初识git:简单介绍及安装流程
git·学习