当我尝试提交时出现了这个错误。
操作系统 - 最新的OSX
Git版本 - git version 2.11.0(Apple Git-81)
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
当我尝试提交时出现了这个错误。
操作系统 - 最新的OSX
Git版本 - git version 2.11.0(Apple Git-81)
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
在尝试提交更改时,pre-commit钩子是首先运行的,并且可以用于执行某些检查、测试和条件。在这种情况下,很明显,你没有它,这就是为什么它在抱怨。
进入.git/hooks
目录并删除pre-commit
文件,因为其正在尝试引用node_modules/pre-commit/hook
。这样应该会解决问题。
另一种选择是在提交中添加选项:--no-verify
,这将使提交时不进行检查。
gem webpacker
和webpack安装过程可能出错了;因为我刚刚做过这个。但奇怪的是pre-commit
文件最后一次修改是六个月前。但移除pre-commit
文件解决了我的问题。 - Gregpre-commit
文件并没有解决。后来我尝试在终端中使用命令提交,并在最后加上 --no-verify
命令,所以我的命令是 git commit -m "message" --no-verify
。这对我有用。 - Komal Goyanigit commit -n(或--no-verify)
绕过Lint检查。 - Rickchip您需要删除node_modules
文件夹,并重新运行npm install
或yarn install
进行安装。之后,您可能会解决问题。
如果脚本文件实际上存在,则可能是因为脚本的第一行应该像这样:
#!/bin/sh
否则,您将得到相同的错误。
任何文件都可以使用 - 例如,/bin/bash
,/usr/local/bin/python3
- 只要它存在且可执行即可。
根据@Mutant的提示,对我来说简单的答案是:
rm .git/hooks/pre-commit
我在使用macOS时遇到一个问题,我的Python3是通过Homebrew安装的。当我通过brew update && brew upgrade
升级Python3后,我仍然遇到了同样的错误。
为了解决这个问题,我需要更新目录中符号链接,使得.git/hooks/pre-commit
文件中的shebang (#!
)指向正确的Python3路径。
以下是我在我的环境中如何解决这个问题:
Look at the contents of the .git/hooks/pre-commit
:
cat .git/hooks/pre-commit
The first few lines should look something like:
#!/usr/local/opt/pre-commit/libexec/bin/python3
# File generated by pre-commit: https://pre-commit.com
# ID: 0123456789abcdef0123456789abcdef
import os
import sys
Take note of the path to the python3
executable in the shebang line:
/usr/local/opt/pre-commit/libexec/bin/
cd
into that directory.
cd /usr/local/opt/pre-commit/libexec/bin/
Take at look at the Python symlinks:
ls -l | grep python
You'll see some symlinks that are probably broken:
lrwxr-xr-x 1 user group 91 Apr 5 13:33 python -> /usr/local/Cellar/python@3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x 1 user group 91 Apr 5 13:33 python3.9 -> /usr/local/Cellar/python@3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x 1 user group 91 Apr 5 13:33 python3 -> /usr/local/Cellar/python@3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/bin/python3.9
Quick note: In case something goes wrong or my answer isn't the solution, you might want to back up these symlinks first by running:
mv python python.bak
mv python3.9 python3.9.bak
mv python3 python3.bak
Update the symbolic links using ln -s [PATH] [LINK]
, where [PATH]
is the location of the Homebrew-updated Python3 executable and [LINK]
is python
, python3.9
, and python3
:
ln -s /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/bin/python3.9 python
ln -s /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/bin/python3.9 python3.9
ln -s /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/bin/python3.9 python3
When you've done that, list your Python symlinks again.
ls -l | grep python
You should see the updated symlinks, and git commit
should now work.
lrwxr-xr-x 1 user group 89 Apr 6 13:58 python -> /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x 1 user group 89 Apr 6 13:58 python3 -> /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x 1 user group 89 Apr 6 13:58 python3.9 -> /usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/bin/python3.9
npm i
rm -rf node_modules
npm i
我在使用brew让Webstorm支持yarn时遇到了这个错误。
解决方法就是重新安装pre-commit。
brew install pre-commit
INGW64 ~/code/ingestor-gdelt (test-build)
$ git commit -m "your comment"
.git/hooks/pre-commit: 第9行:py:命令未找到
.git/hooks/pre-commit: 第10行:py:命令未找到
git commit --no-verify -m "your comment"
这个命令解决了我的问题!!
pre-commit install
。
.git/hooks/pre-commit
中),它正在尝试引用不存在的./node_modules/pre-commit/hook
。如果不再需要该钩子,您可以直接将其删除。 - c3st7n