今天想通过 brewopenvc,结果发现根本 search 不到。
但是网上搜索怎么安装这个库,的确都是用 brew,所以想更新一下 brew 再搜。

结果更新直接报错如下:

brew update

fatal: Could not resolve HEAD to a revision

Already up-to-date.

看似 Already up-to-date.,实际上什么都没更新下来。
解决方法如下:

1. 找到更新时候出错的路径。

brew update --verbose

Checking if we need to fetch /usr/local/Homebrew...

Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...

Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...

Fetching /usr/local/Homebrew...

Updating /usr/local/Homebrew...

Branch 'master' set up to track remote branch 'master' from 'origin'.

Switched to and reset branch 'master'

Your branch is up to date with 'origin/master'.

Switched to and reset branch 'stable'

Current branch stable is up to date.

Updating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...

fatal: Could not resolve HEAD to a revision

Already up-to-date.

不难看出出错的路径是 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

2. 手动更新出错路径仓库

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

git fetch --prune origin

git pull --rebase origin master

From https://github.com/Homebrew/homebrew-core

* branch                    master     -> FETCH_HEAD

pull 成功后,就已经更新完成,不放心的可以再执行一下 brew update 看还有没有报错。
更新完后,自然可以正常安装 opencv 了。

PS: 建议更换国内源,有强迫症的可以临时更换。

# 临时替换:
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"

# 永久替换
# 对于 bash 用户
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.bash_profile

# 对于 zsh 用户
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.zshrc

参考:

  1. https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
  2. https://mirrors.ustc.edu.cn/help/homebrew-bottles.html