brew 更新时遇到 shallow clone异常

403 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第1天,点击查看活动详情

场景

本来打算安装个工具的,结果也出现以下问题,我尝试更新 brew 也出现同样问题。

问题

❯ 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

结果没任何反应,什么原因?可能是系统更新造成的,也可能是 homebrew 默认源的问题,虽然我这样有梯子,还是慢,也有可能被墙....., 原因找到,这里我先换下源试试。

网上找了清华源和阿里云的镜像,发现两家都不全,后来发现中科院镜像比较全:感兴趣的同学可以自己看看。

解决方案

我这里直接选择在~/.bash_profile文件中更新brew 源,更新后执行source .bash_profile下即可。实例如下:

 # homebrew  
export ORIGIN = "https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git/"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
# homebrew end

更新完我们通过brew config看下结果:

HOMEBREW_VERSION: 3.3.2-2-gb14078a
ORIGIN: https://github.com/homebrew/brew.git
HEAD: b14078a41d29a606ade14f03fdd9ddfe36114526
Last commit: 11 months ago
Core tap ORIGIN: https://mirrors.ustc.edu.cn/brew.git
Core tap HEAD: 8a12f10b8378933094c45fbe40aa9900c6a269fc
Core tap last commit: 3 years, 6 months ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_BOTTLE_DOMAIN: https://mirrors.ustc.edu.cn/homebrew-bottles
HOMEBREW_BREW_GIT_REMOTE: https://mirrors.ustc.edu.cn/brew.git
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://mirrors.ustc.edu.cn/homebrew-core.git
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.8 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/bin/ruby
CPU: quad-core 64-bit broadwell
Clang: 11.0.3 build 1103
Git: 2.16.1 => /usr/local/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.6-x86_64
CLT: 11.3.0.32.62
Xcode: N/A

源已经更新了,先测试 homebrew-core ,结果还是不行,而 homebrew-cask 可以更新了,先看看 homebrew-coret提示问题: image.png 这也不知道啥问题的导致,我干脆直接把原来目录里的homebrew-core删了,让后重新执行 brew upgrade,不过这过程可能有点慢,中间也可能有些包安装会中断,比如:

image.png

image.png 出现中断,手动安装下这些包即可。 更新完了,结果已经更新到最新 3.6.3版本了。 image.png

就这些了, 走过路过的同学,觉得对你有帮助别玩忘了点个小小的👍哟,Thanks♪(・ω・)ノ 。

相关资料