当前位置: 首页 > 工具软件 > Agit > 使用案例 >

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

曾鸿振
2023-12-01

1.执行 brew install xxx 命令报错

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

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. 如果碰到了下面的错误

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 中输入下面的命令即可

export HOMEBREW_BOTTLE_DOMAIN=""
 类似资料: