macOS卸载Xcode导致git报错的解决方法

因为macbook空间不足卸载了没怎么用的Xcode,导致下班前提交代码时发现git报以下错误:

1
xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer), missing xcrun at: /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun

经过一番尝试,发现git依赖的CommandLineTools命令行工具路径指向的是Xcode。我们可以通过xcode-select -p查看。那么此时我们先把它装回来,执行:
1
xcode-select --install

看下安装成功了没:
1
2
xcode-select --version
-> xcode-select version 2354.

然后把系统命令行路径重新指向到刚安装的xcode-select目录:
1
sudo /usr/bin/xcode-select  --switch /Library/Developer/CommandLineTools

好了,试试git回来了没:
1
2
git --version
-> git version 2.20.1 (Apple Git-117)

Done.


macOS卸载Xcode导致git报错的解决方法
http://yanziyu.fun/2019/07/16/mac-git/
作者
Leo Yen
发布于
2019年7月16日
许可协议