git:找不到命令(在 OS X 10.5 上)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1835837/
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-10 07:27:10  来源:igfitidea点击:

git: command not found (on OS X 10.5)

gitmacos

提问by James P. Wright

I am receiving this error when I try to use git lately. I'm not exactly sure when the error started as I rarely use git. I used to use it. I didn't change anything about it or my machine that I know of. Now it doesn't work.

我最近尝试使用 git 时收到此错误。我不确定错误何时开始,因为我很少使用 git。我曾经使用它。我没有改变它或我所知道的我的机器。现在它不起作用。

I've gone through and reinstalled the latest version using thisinstaller, and I still get the same error in terminal.

我已经使用安装程序重新安装了最新版本,但在终端中仍然出现相同的错误。

Anyone heard of this before? The installer runs just fine, no errors, but it still doesn't recognize the "git" command in terminal.

有人听说过这个吗?安装程序运行得很好,没有错误,但它仍然无法识别终端中的“git”命令。

I'm running OS 10.5

我正在运行 OS 10.5

EDIT

编辑

Per a response down below which pointed me to my PATH variable I think that's the issue. I installed MacPorts at one point, which changed my .profile I have no idea how to change it back though. My old .profile was this:

根据下面的回复,我指出我的 PATH 变量,我认为这就是问题所在。我曾经安装了 MacPorts,这改变了我的 .profile 我不知道如何将它改回来。我的旧 .profile 是这样的:

alias g='git'
export PS1='$(git branch &>/dev/null; if [ $? -eq 0 ]; then \
echo "\[3[00m\]$(git branch grep ^*sed s/\*\ //) "; fi)$\[3[00m\] '
export LC_CTYPE=en_US.UTF-8
export PATH=$PATH:/usr/local/bin

My new .profile is this:

我的新 .profile 是这样的:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

How can I make those two files become one?

我怎样才能使这两个文件合二为一?

回答by Josh Lee

From the page you linked to:

从您链接到的页面:

/usr/local/git/bin

Is that in your PATH?

那在你的PATH中吗?

Open ~/.profilein your favorite editor and add the line

~/.profile在您喜欢的编辑器中打开并添加行

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

This appends the item to your PATH variable (separarated by colons), so it's compatible with other commands that modify the path.

这会将项目附加到您的 PATH 变量(由冒号分隔),因此它与修改路径的其他命令兼容。

回答by Alon Shacham

Had the same issue on mountain lion.

在山狮上有同样的问题。

If yo're using XCode, run it. then go to XCode->preferences and install "Command Line Tools".

如果您使用的是 XCode,请运行它。然后转到 XCode-> 首选项并安装“命令行工具”。

thats it, worked for me.

就是这样,对我来说有效。

http://www.hongkiat.com/blog/mountain-lion-git-fix/

http://www.hongkiat.com/blog/mountain-lion-git-fix/

回答by Courtney Faulkner

Another way to approach this is to check to see if you have an /etc/paths.d/gitfile. The OSX installer should have created that file containing:

解决此问题的另一种方法是检查您是否有/etc/paths.d/git文件。OSX 安装程序应该已经创建了包含以下内容的文件:

/usr/local/git/bin

/usr/local/git/bin

so that it is picked up without any .bash_profile needed, or at least no special entries in your .bash_profile, or .profile in your case.

以便在不需要任何 .bash_profile 的情况下提取它,或者至少在您的 .bash_profile 或 .profile 中没有特殊条目。

I just tested deleting my .bash_profile and opening a fresh shell window and I'm still able to resolve the gitcommand.

我刚刚测试了删除我的 .bash_profile 并打开一个新的 shell 窗口,我仍然能够解析git命令。

回答by devlord

What worked for me was

对我有用的是

  1. Installing the latest version of Xcode from the App Store
  2. Running alias git='xcrun git'per this guy.
  1. 从 App Store 安装最新版本的 Xcode
  2. 运行alias git='xcrun git'每个这个家伙

回答by tquach

In case people still get this problem, make sure the /usr/libexec/path_helper is executable. I had this problem when I installed Prezto.

如果人们仍然遇到这个问题,请确保 /usr/libexec/path_helper 是可执行的。我在安装 Prezto 时遇到了这个问题。

sudo chmod ugo+x /usr/libexec/path_helper

回答by anataliocs

Navigate to your home directory:

导航到您的主目录:

cd ~

You can verify you are in the correct directory by printing your working directory:

您可以通过打印您的工作目录来验证您位于正确的目录中:

pwd

It should output something like: /user/YOUR_USER

它应该输出类似: /user/YOUR_USER

Then open up your bash profile:

然后打开你的 bash 配置文件:

vi .bash_profile

You should see something like the following:

您应该会看到类似以下内容:

Bash Profile VI

Bash 配置文件 VI

Then press 'i' to enter insert mode

然后按“i”进入插入模式

insert mode

插入模式

Then add your export to the file(You can use COMMAND+cand COMMAND+vto copy paste):

然后将您的导出添加到文件中(您可以使用COMMAND+cCOMMAND+v复制粘贴):

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

Then press the 'esc' button -> then type in the following to write your changes and quit:

然后按“esc”按钮 -> 然后输入以下内容以写入更改并退出:

:wq

Then press enter.

然后按回车。

Next, you will need to close and quit the terminal and then open a new one.

接下来,您需要关闭并退出终端,然后再打开一个新终端。

回答by Luiz Dias

In my case, there was nothing wrong with my path, but whether XCode is correctly installed or not.

就我而言,我的path.js没有任何问题,但是否正确安装了 XCode。

In the Terminal (Applications > Utilities > Terminal), type and run:

在终端(应用程序 > 实用工具 > 终端)中,输入并运行

xcode-select --install

This command will download and install XCode Developer Tools and you won't see that message again.

此命令将下载并安装 XCode 开发人员工具,您将不会再次看到该消息。

Or, depending on where you problem lies, running the following command may also help:

或者,根据您的问题所在,运行以下命令也可能有所帮助:

xcode-select --reset

Hope it helps!

希望能帮助到你!