解决 Mac brew install xxx fatal: not in a git directory 问题

2022-08-11 18:25:33 浏览数 (1)

1.执行 brew install xxx 命令报错

代码语言:shell复制
fatal: unsafe repository ('/usr/local/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 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
fatal: unsafe repository ('/usr/local/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 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
fatal: unsafe repository ('/usr/local/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 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services
fatal: unsafe repository ('/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services' is owned by someone else)
To add an exception for this directory, call:
...
...
...
fatal: not in a git directory
Error: Command failed with exit 128: git

2. 解决方案

按照错误提示,进行git config

代码语言:shell复制
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-caskgit 

3.最后在执行 brew install xxx 就可以了

4. 如果碰到了下面的错误

代码语言:shell复制
tar: Error opening archive: Failed to open '/Users/didi/Library/Caches/Homebrew/downloads/fee13f1bfa4b2a3b6f32e14e9f0cb1b6bf34cfdc2d571d047331872c9b940807--apr-util-1.6.1_3.big_sur.bottle.tar.gz'
Error: Failure while executing; `tar --extract --no-same-owner --file /Users/didi/Library/Caches/Homebrew/downloads/fee13f1bfa4b2a3b6f32e14e9f0cb1b6bf34cfdc2d571d047331872c9b940807--apr-util-1.6.1_3.big_sur.bottle.tar.gz --directory /private/tmp/d20220811-11463-19frpj7` exited with 1. Here's the output:
tar: Error opening archive: Failed to open '/Users/didi/Library/Caches/Homebrew/downloads/fee13f1bfa4b2a3b6f32e14e9f0cb1b6bf34cfdc2d571d047331872c9b940807--apr-util-1.6.1_3.big_sur.bottle.tar.gz'

临时修改去掉国内的镜像设置: 在 Terminal 中输入下面的命令即可

代码语言:shell复制
export HOMEBREW_BOTTLE_DOMAIN=""

0 人点赞