【macOS】Git 2.35.2修复安全漏洞导致brew无法正常使用解决方案
✨Homebrew
关于 Homebrew 介绍详见如下博客
【macOS】Homebrew & Homebrew cask macOS软件包管理神器 - 双份浓缩馥芮白 - 博客园 (cnblogs.com)
✨更新macOS 12.4后brew无法正常使用
brew update
无法正常运行
提示如下
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-cask, skipping update!
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-core, skipping update!
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
brew install
也无法正常使用
报错提示如下
最初以为是homebrew
的问题
重新安装了brew
问题依旧
Homebrew安装使用的是 Homebrew国内如何自动安装(国内地址)(Mac & Linux)
✨更换brew源时发现问题原因
尝试更换brew源
首先使用brew doctor
分析无法正常使用的原因
提示如下
考虑更换brew源
(因为如果按照Warning中提示会重新安装brew 之前已经尝试过 并没有解决问题)
Homebrew更换国内源可参考
【macOS】Homebrew更换国内源 - 双份浓缩馥芮白 - 博客园 (cnblogs.com)
替换为清华源
# 替换各个源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C "$(brew --repo homebrew/cask-versions)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git
# zsh 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# bash 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# 更新源
brew update
Homebrew国内自动安装脚本 最新版本最后的源是写入.zprofile
中的
因此 zsh 替换 brew bintray 镜像
命令应当更改如下
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zprofile
source ~/.zprofile
Git 2.35.2 修复安全漏洞
运行如下两行命令时注意到反馈提示
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
(base) ➜ ~ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
(base) ➜ ~ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
fatal: unsafe repository ('/opt/homebrew/Library/Taps/homebrew/homebrew-core' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
(base) ➜ ~ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
fatal: unsafe repository ('/opt/homebrew/Library/Taps/homebrew/homebrew-cask' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
(base) ➜ ~
Git 2.35.2
修复了 CVE-2022-24765 安全漏洞
(显然 Apple 在macOS 12.4中更新了Git)
所以导致homebrew
、homebrw-cask
无法正常使用
参考:
因此解决方案如下
✨解决方案
根据提示
fatal: unsafe repository ('/opt/homebrew/Library/Taps/homebrew/homebrew-core' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
fatal: unsafe repository ('/opt/homebrew/Library/Taps/homebrew/homebrew-cask' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
运行如下命令添加 Git 信任目录homebrew-core
、homebrew-cask
、homebrew-services
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-services
运行如下命令可查看 Git 全局配置
git config --global --list
再次运行brew update
与brew
相关命令
如图所示
问题已解决。
⭐转载请注明出处
本文作者:双份浓缩馥芮白
原文链接:https://www.cnblogs.com/Flat-White/p/16334642.html
版权所有,如需转载请注明出处。