bash 未找到“预提交”命令,但 macOS 上安装了该命令

问题描述 投票:0回答:5

问题描述

当我尝试使用以下命令进行提交时,我在提交时遇到问题,例如:

$ git commit -m "add readme"
pre-commit not found. Install pre-commit with the command pip3 install --user pre-commit or follow the steps on official documentation: https://pre-commit.com /#install

按照我通过命令安装的预提交安装文档中描述的步骤:

$ pip install pre-commit

但是,当我触发命令时,会发生以下错误:

$ pre-commit --version
bash: pre-commit: command not found

我的尝试失败了,所以我尝试了一些其他解决方案,但它们不起作用。

出口狂欢:

我已经尝试过这个解决方案描述了使用以下命令导出我的

~./bashrc
source ~/.profile
但是发生以下错误:

bash:/Users/pvieira/.profile: No such file or directory

使用自制软件安装:

这会导致与上面通过

pip
手动安装时发生的错误相同。

bash git git-commit pre-commit pre-commit.com
5个回答
4
投票

我只需重新启动终端即可解决问题。


0
投票

未找到命令

此错误通常意味着您的 shell 无法在其哈希中找到匹配的可执行文件,或者该文件不再位于以前的位置。 shell 在加载时会在

PATH
环境变量中创建所有程序的哈希值。

根据您的 shell,您可以通过运行

hash
rehash
来刷新其哈希值。

重新加载 shell 或终端可以解决问题的原因是,它实际上创建了一个新的哈希值。同样,重新启动计算机也会重新创建一个新的哈希值。


0
投票

我用过MacOS。我通过

brew install pre-commit

安装预提交解决了这个问题

0
投票

对我来说,问题是我使用了 pip install 而不是 pip3 install,后者没有使用默认的 python 版本。将其添加到 bash 配置文件并重新启动 bash 后,它开始工作

alias python='python3'
alias pip='pip3'

-1
投票

我通过重新启动我的ubuntu系统解决了这个问题

© www.soinside.com 2019 - 2024. All rights reserved.