I am using win10.
when clicking the blue button on the Github desktop to commit something.
error husky - pre-commit hook exited with code 1 (error)
appears.
But if i type git commit -m "sth" in terminal, the pre-commit hook works fine
=============================
part of my package.json
"lint-staged": {
"*.{js,jsx,tsx,ts}": "eslint --cache --fix",
"*.{js,css,md,jsx,tsx,ts}": "prettier --write"
}
============================
.husky/pre-commit.sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
============================
.husky/_/husky.sh
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
if [ "$HUSKY_DEBUG" = "1" ]; then
echo "husky (debug) - $1"
fi
}
readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."
if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi
if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi
export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"
if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
fi
exit $exitCode
fi
The issue (even though it's not a real issue! ) is because of the hooks created by Husky. Husky is an npm package that lets you define npm scripts that correlate to local Git events such as a commit or push. And this helps in enforcing collaborative standards in a project. The quick solution, if you are too busy, is to simply delete the hooks folder for git which defines the pre-commit hooks and hence can push after that. (This is just kind of a hack to avoid editing thousands of files at a time for lint errors. Follow the guidelines and resolve all the lint errors for better code quality and maintainability. ) But it's always better to understand how Husky and hooks work and properly follow the lint warnings.
Edit: You can also skip hooks when you provide the git command line argument —no-verify,
, or use Sourcetree‘s Bypass commit hooks setting (in the menu to the top right of the commit message field)