无法从终端使用 git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19887445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:20:06  来源:igfitidea点击:

Cannot use git from terminal

macosgitgithub

提问by Cranialsurge

I installed the GitHub UI for OS X from here: https://central.github.com/mac/latest. As part of the installation I get an option to "Install Command Line Tools". On doing so it places the relevant assets under /usr/local/bin. I assumed it would register git in the PATH variable as well so that I could run it from the terminal if needed. However it doesn't work from the terminal, instead if I run 'git' in terminal, I get prompted to install XCode.

我从这里安装了 OS X 的 GitHub UI:https: //central.github.com/mac/latest。作为安装的一部分,我可以选择“安装命令行工具”。这样做时,它会将相关资产放在 /usr/local/bin 下。我假设它也会在 PATH 变量中注册 git,以便我可以在需要时从终端运行它。但是,它在终端中不起作用,相反,如果我在终端中运行“git”,则会提示我安装 XCode。

Am I assuming something incorrectly here? Also tried installing git from here: http://git-scm.com/download/mac. After the installer completed successfully, I still can't seem to be able to use git from the terminal.

我在这里假设错误吗?还尝试从这里安装 git:http: //git-scm.com/download/mac。安装程序成功完成后,我似乎仍然无法从终端使用 git。

UPDATE: my PATH variable has the following:

更新:我的 PATH 变量具有以下内容:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

回答by VonC

As mentioned in "git on Mac: replace Apple XCode CLI git with symbolic link to latest git install?", it dpeends on the order of the folders in the PATHenvironment variable.

如“ Mac 上的 git:将 Apple XCode CLI git 替换为最新 git 安装的符号链接?”中所述,它取决于PATH环境变量中文件夹的顺序。

  • XCode CLI installer puts a copy of git in /usr/bin
  • Reinstalling the latest git from git-scm.com put git in /usr/local/git/bin/git
  • XCode CLI 安装程序将 git 的副本放入 /usr/bin
  • 从 git-scm.com 重新安装最新的 git 将 git 放入 /usr/local/git/bin/git

If git command line is installed in /usr/local/git/bin, make sure to put that in first:

如果 git 命令行安装在 中/usr/local/git/bin,请确保先将其放入:

PATH=/usr/local/git/bin:$PATH

回答by averem

Just download these tools running command in terminal:

只需在终端下载这些运行命令的工具:

xcode-select --install

If it doesn't help you try to download them manually form apple developer site: https://developer.apple.com/downloads/index.action?=command%20line%20tools#

如果它不能帮助您尝试从苹果开发者站点手动下载它们:https: //developer.apple.com/downloads/index.action?=command%20line%20tools#

It helped me.

它帮助了我。