我更新了最新的操作系统,和/或重新启动了我的计算机(每次重大更新都会发生这种情况,但这次我所做的只是在2022-09-13年重新启动我的计算机)

今天早上,我在MacBook pro的命令行中导航到我的工作代码库,在存储库中键入“gitstatus”,收到一个错误:

(2022年9月,这个错误大不相同,但我没有捕捉到它)

xcrun:错误:无效的活动开发人员路径(/Library/developer/CommandLineTools),在以下位置缺少xcrun:/Librari/developer/CommandLineTools/usr/bin/xcrun

git不起作用!

如何修复git和命令行工具?


当前回答

M1的后续工作

ProductName:    macOS
ProductVersion: 11.2.1
BuildVersion:   20D74

% xcode-select --install

同意“条款和条件”提示,成功后将返回以下消息。

% xcode-select: note: install requested for command line developer tools

其他回答

这是在我将Macbook pro升级到macOS Ventura之后发生的。升级后,git命令行停止工作,并显示此消息。

xcrun:错误:无效的活动开发人员路径(/Library/Developer/CommandLineTools),在以下位置缺少xcrun:/库/开发人员/命令行工具/usr/bin/xcrun

运行brew升级修复了git命令行。

打开终端:

安装XCode开发人员工具并解决问题。

$ xcode-select --install

如果您有多个版本,请将路径重置为Xcode:

$ xcode-select --switch /Applications/Xcode.app
$ xcode-select --switch /Library/Developer/CommandLineTools

对我来说,xcode select--reset是Mojave上的解决方案。

如果您手动下载了Xcode(即不是从App Store下载)或根本没有Xcode:

sudo rm-rf/库/开发人员/命令行工具去https://developer.apple.com/download/more/下载Xcode 10的命令行工具(macOS 10.14)设置命令行工具

如果您从App Store安装了Xcode:

xcode select--安装

对于使用Catalina和Xcode beta的用户:

sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer