git: early EOF
macOS报错:
Initialized empty Git repository in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/
remote: Enumerating objects: 2691797, done.
remote: Counting objects: 100% (1760/1760), done.
remote: Compressing objects: 100% (636/636), done.
error: RPC failed; curl 56 Recv failure: Connection reset by peers
error: 1650 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
原因:网络不良或者缓冲区太小。
解决方法:
这个错误表明在从 GitHub 拉取 Homebrew 核心仓库时,网络连接被对方重置(Connection reset by peer
),通常是由于网络不稳定、连接超时或 GitHub 服务器负载过高导致的。以下是针对性的解决方案:
1. 增加 Git 的 HTTP 缓冲区大小
Git 默认缓冲区较小,大文件传输时容易中断。增大缓冲区:
git config --global http.postBuffer 1048576000 # 1GB
2. 禁用 Git 的压缩功能
压缩可能导致传输不稳定,临时禁用:
git config --global core.compression 0
3. 调整 HTTP 相关参数
增加超时时间并允许重试:
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999
git config --global http.maxRequests 50
git config --global http.maxRetries 5
git config --global http.retryDelay 5
4. 使用代理(如果需要)
如果网络需要代理,设置 HTTP/HTTPS 代理:
# 临时设置(当前终端会话有效)
export HTTP_PROXY=http://proxy.example.com:port
export HTTPS_PROXY=http://proxy.example.com:port# 或为 Git 单独设置代理
git config --global http.proxy http://proxy.example.com:port
git config --global https.proxy http://proxy.example.com:port
替换 proxy.example.com
和 port
为你的代理服务器地址和端口。
5. 使用国内镜像源(针对中国大陆用户)
切换到清华大学镜像源以提高稳定性:
# 重置 Homebrew 核心仓库为清华大学镜像
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git# 重新更新
brew update
6. 手动下载仓库(最后手段)
如果网络问题持续存在,可以手动下载并替换仓库:
# 备份现有仓库
cd "$(brew --repo)/Library/Taps/homebrew"
mv homebrew-core homebrew-core-bak# 克隆清华大学镜像仓库
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git# 更新 Homebrew
brew update
7. 完成后重置配置
问题解决后,可恢复默认 Git 配置:
# 重置缓冲区大小
git config --global --unset http.postBuffer# 重置压缩设置
git config --global --unset core.compression# 重置代理(如果设置过)
git config --global --unset http.proxy
git config --global --unset https.proxy
测试网络连接
在操作前,建议测试 GitHub 连接稳定性:
# 测试 ping
ping github.com# 测试端口连通性
nc -vz github.com 443
如果连接不稳定,尝试切换网络环境(如从 Wi-Fi 切换到移动网络)。
如果上述方法仍然无法解决问题,可能是 GitHub 服务临时故障或本地网络限制,建议稍后重试或联系网络管理员。