brew update 报错:This restriction has been made on GitHub's request because updating shallow clones...

问题:

Mac 下执行 brew update 时,报如下错误:

Error:
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

如果只需按上述提示执行相应命令即可:

  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow

但是 git 仓库是国外的,速度慢,还经常被墙,导致 early EOF 之类的错误。

更换数据源:

## 更新 homebrew-cask
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask

## 更换源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

## 更新,由于已经 cd 到相应文件夹了,因此不需要通过 -C 指定路径了
git fetch --unshallow 

## 更新 homebrew-core
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-core

## 更换源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
## 更新
git fetch --unshallow 

如果还不能更新,执行如下命令查看远端 repo 是不是设置错了。

git remote -v 

最后执行 brew update 即可。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容