当我的mac使用Git提交代码时,被哈士奇拒绝,提示`sh:command not found`
when my mac commits code using Git, rejected by Husky, prompt ` sh:command not found `
当我的 Mac 使用 Git 提交代码时,它被 Husky 拒绝,我看到以下错误:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
.husky/_/husky.sh: line 23: sh: command not found
husky - pre-commit hook exited with code 127 (error)
终端或VSCode也报错。
我怎样才能克服这个错误?
这大约是 github.com/typicode/husky/husky.sh#L23
sh -e "[=10=]" "$@"
确保 sh 在您的 $PATH
中(通常 /bin/sh
)
将 echo "prg='[=16=]'"
添加到您的 .husky/_/husky.sh
只是为了调试并检查它是否是未找到的“$0”(为空)
然后检查路径问题,issue 912
我使用 VS Code 和 Husky v6。
I ran echo $PATH
from the root of my project.
Then I copied the output to the pre-commit
file in the .husky
directory.
My pre-commit file looks like this:
#!/bin/sh
. "$(dirname "[=11=]")/_/husky.sh"
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
npx lint-staged
如 OP 所述,参考 Husky/ Command not found,~/.huskyrc
应正确设置 NVM:
# ~/.huskyrc
# This loads nvm.sh and sets the correct PATH before running hook
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
当我的 Mac 使用 Git 提交代码时,它被 Husky 拒绝,我看到以下错误:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
.husky/_/husky.sh: line 23: sh: command not found
husky - pre-commit hook exited with code 127 (error)
终端或VSCode也报错。
我怎样才能克服这个错误?
这大约是 github.com/typicode/husky/husky.sh#L23
sh -e "[=10=]" "$@"
确保 sh 在您的 $PATH
中(通常 /bin/sh
)
将 echo "prg='[=16=]'"
添加到您的 .husky/_/husky.sh
只是为了调试并检查它是否是未找到的“$0”(为空)
然后检查路径问题,issue 912
我使用 VS Code 和 Husky v6。
I ran echo
$PATH
from the root of my project.
Then I copied the output to thepre-commit
file in the.husky
directory.My pre-commit file looks like this:
#!/bin/sh . "$(dirname "[=11=]")/_/husky.sh" export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" npx lint-staged
如 OP 所述,参考 Husky/ Command not found,~/.huskyrc
应正确设置 NVM:
# ~/.huskyrc
# This loads nvm.sh and sets the correct PATH before running hook
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"