Mac下使用git命令报xcrun: error问题解决

in 互联网技术 with 0 comment  访问: 86 次
crh:githome crh$ git branch
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

问题分析:
初步怀疑是不是git命令有问题了,或者说git命令的依赖库什么的有问题

crh:githome crh$ which git
/usr/bin/git
crh:githome crh$ git -h
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

如上可以看出命令是正常被安装,但是执行起来还是报xcrun: error: invalid active developer path 的错误。

还有问题那就尝试重新安装一下git,看看是否会解决此类错误, 不幸的是还是报错:

Error: The following formula:
  git
cannot be installed as a binary package and must be built from source.
Install the Command Line Tools:
  xcode-select --install

Error: Git must be installed and in your PATH!
Error: The following formula:
  git
cannot be installed as a binary package and must be built from source.
Install the Command Line Tools:
  xcode-select --install

从上面信息可以看出提示:不能作为二进制包安装,必须从源代码构建,需要在命令行执行xcode-select --install 来安装xcode-select.

在终端执行xcode-select --install会跳出来安装界面,安装完成后,就可以用了。

crh:githome crh$ git -h
unknown option: -h
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

如上所示输出相应的帮助信息,意味着git已经被修复好了,可以使用了。

WeZan
Responses