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

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

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

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

git不起作用!

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


当前回答

凭借之前的应用程序开发经验,我可以放心地说,与苹果一起交付的git版本总是会带来问题。所以,你越早摆脱苹果吉特越好,所以我可以建议:

brew uninstall git
brew update
brew install git

# which git
/usr/local/bin/git

其他回答

对我来说,这发生在Mac OS更新到Mojave之后,git在Intellij中无法运行

解决方案:-转到“设置”,然后选择“文件”|“设置”|“版本控制”|“Git”,然后编辑“Git可执行文件的路径”字段,该字段为/usr/local/bin/Git

M1的后续工作

ProductName:    macOS
ProductVersion: 11.2.1
BuildVersion:   20D74

% xcode-select --install

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

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

除了dustbuster的答案,我还需要使用以下命令设置Xcode文件夹的路径:

sudo xcode-select -switch /Library/Developer/CommandLineTools

对于Ventura 13.0.1。

macOS Ventura 13.0.1更新(2022年11月)为Xcode 14.1安装命令行工具

这对我有用

凭借之前的应用程序开发经验,我可以放心地说,与苹果一起交付的git版本总是会带来问题。所以,你越早摆脱苹果吉特越好,所以我可以建议:

brew uninstall git
brew update
brew install git

# which git
/usr/local/bin/git