husky > pre-commit hook failed (add --no-verify to bypass)
Asked Answered
V

10

95

Suddenly I am getting the "husky > pre-commit hook failed (add --no-verify to bypass)" error message when I give the git commit.

(C:\Windows\System32\cmd.exe)
> git commit
husky > npm run -s precommit (node v12.18.3)

'pretty-quick' is not recognized as an internal or external command,
operable program or batch file.

husky > pre-commit hook failed (add --no-verify to bypass)

I tried git clean command too. Anyone faced similar issue?

Viborg answered 17/9, 2020 at 17:35 Comment(1)
You can also delete the .git/hook folder and then uninstall and reinstall husky. There are some conflicts with husky generated files and .git/hook/ files. That worked for meEnjoyable
V
216

Husky can prevent you from bad git commit, git push, and more. If you are getting this error check your code syntax. In case you are getting this error even if your code is valid, please use the below solution.

#Solution 1:

Delete the .git/hooks folder and then do the npm install to reinstall husky. There are chances for conflicts with husky-generated files in the .git/hooks/ files.

#Solution 2:

this is a temporary/quick solution.

git commit -m "message" --no-verify
Viborg answered 18/9, 2020 at 3:25 Comment(14)
It's helped me while no need to check any code syntax and other lints. Thank you @SathiaPsychomotor
delete the .git/hook folder in project directory and tried code committing it again and it worked for me like a charm. Thanks !!Chaos
Deleted .git/hooks folder and committed again. This worked for me as wellBraswell
It's hooks plural. Deleting it worked for me. Thanks!Scrivings
delete the .git/hooks worked for me as well!Coparcenary
why would I want to add --no-verify everytimeKhoisan
deleting .git/hooks worked for me too!Cortisone
You don't even have to reinstall husky. I had to remove .git/hooks and was able to commitMasao
Because I changed from using npm to yarn, thus has this issue, but fixed with this": Delete the .git/hook folder and then do the npm install for reinstall husky. There are chances for conflicts with husky-generated files and .git/hook/ files.Clino
Wonderful solutions, first solutions worked, 2nd not needed to try for me! ThanksMatriarch
In case someone stumbles to this place looking for help on php-husky, it was failing for me because .git direcotory didn't exist.Steelhead
git config --unset core.hooksPathDrabbet
how/where to find this folder "git/hook"?Rann
The first solution didn't work for me. As for the second, is there already some way to not write all the time --no-verify? It works but it stresses me outInternuncial
I
11

I find two temporary solution like that

git config --unset core.hooksPath  

or

git commit -m "message" --no-verify 
Impuissant answered 30/12, 2021 at 8:36 Comment(1)
The first command worked for me, but what does it do exactly?Draughtsman
B
8

The Comment by @Elio is a much preferred solution, as --no-verify is skipping whatever scripts that should run.

I assume here that if the scripts are there it is for a reason...

Therefore:

You can also delete the .git/hook folder and then uninstall and reinstall husky. There are some conflicts with husky generated files and .git/hook/ files. That worked for me

In my case, the uninstall/re-install was not necessary.

Boudreaux answered 27/4, 2021 at 10:1 Comment(0)
R
6

In my case, I started getting husky > pre-commit hook failed (add --no-verify to bypass) once some dependencies have been updated. The problem was solved by changing Husky's pre-commit linting command to npm run lint (usually this one works fine in most cases) in the Husky file:

// .huskyrc.json
{
  "hooks": {
      "pre-commit": "npm run lint"
  }
}

Note: the solution works if the lint script is declared in your package.json; in my case I have:

// package.json
{
  "scripts": {
    "lint": "tsc && eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix"
  }
}
Rashid answered 16/9, 2021 at 6:45 Comment(0)
E
3

For me I had to add

"lint-staged": {
  "**/*": "prettier --write --ignore-unknown"
},

to my package.json

Emulation answered 8/6, 2022 at 5:43 Comment(1)
You forgot to add that lint-staged is a separate npm packageGentianaceous
C
1

I came with the same annoying error message when commit to a electron.js project. Adding --no-verify option works, but it's also a bit annoying that I have to do it everytime when commit.

Then I found the something related to precommit in package.json file:

{
  "scripts": {
    ...
    "precommit": "lint-staged",
    ...
  }
}

Just remove the above line solved my problem.

Costermonger answered 13/1, 2022 at 3:18 Comment(2)
i suppose it switch off husky hook, similar to remove hooks from .git folder. this way just bypass the problem but not solving itKensell
@ArtemVertiy Husky no longer supports precommit hooks in package.json, hooks are defined in .husky folderEnneahedron
P
0

This solution worked for me on NestJS application. Use prettier version 2 instead of version 3.

My solution:

npm i -D  [email protected]
Planetesimal answered 28/8, 2023 at 11:27 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Progenitive
I
0

One of the reasons why it happens is because your pre-commit file contains npm test and if you don't have any tests then you will get this error. The way to fix it is either to add tests or remove npm test from pre-commit file or add some another your script like npm run lint

Internuncial answered 30/8, 2023 at 15:29 Comment(0)
S
0

In my case, I was also seeing:

sh: eslint: command not found

which I fixed with:

npm install -g eslint   

Then the error with husky disappeared.

Sultana answered 20/12, 2023 at 20:18 Comment(0)
S
0

I deleted .git/hooks and that helps me. install/uninstall nothing.

rm -rf .git/hooks
Shuping answered 12/3 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.