Homebrew|update 失败 homebrew-core/cask is a shallow clone

#Homebrew手册 穿卡芦苇

环境:macOS V11.1 (Big Sur)

发生的问题

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
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!
...

解决 shallow 问题

按照提示执行git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow,而往往等待很久后,还总是失败。 报错内容类似:

fatal: unable to access 'https://github.com/Homebrew/homebrew-core.git/': transfer closed with outstanding read data remaining

这通常是因为要下载的文件包比较大,因为国内网速问题,耗费时间过长而失败。

解决 unshallow 因下载速度慢而失败:

1,打开目录“/usr/local/Homebrew/Library/Taps/homebrew/”,删除“homebrew-core”和“homebrew-cask”

2,使用第三方加速通道重新 clone 这两个仓库

  • git clone https://github.com.cnpmjs.org/Homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
  • git clone https://github.com.cnpmjs.org/Homebrew/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask --depth=1  

3,再执行 unshallow 命令

  • git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  • git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
      这时候会自动通过 cnpmjs.org 这个加速通道下载所需的软件包。  

等待,完成。


相关参考: https://discourse.brew.sh/t/i-have-problem-with-installation-please-help-me/2906/6


(正文结束。芝士就是力量!