78

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?

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
  • 2
    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 – Elio Apr 12 '21 at 10:47

8 Answers8

175

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 for 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
Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
7

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.

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
manandearth
  • 804
  • 1
  • 9
  • 25
6

I find two temporary solution like that

git config --unset core.hooksPath  

or

git commit -m "message" --no-verify 
Zerzavot
  • 135
  • 1
  • 3
4

I'm surprised that the top answer suggests just to omit hooks' verification. If you have Husky hooks, you cannot just ignore them.

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 husky file:

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

Note: the solution works if 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"
  }
}
Dzmitry Alifer
  • 409
  • 1
  • 6
  • 17
2

For me I had to add

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

to my package.json

pfcodes
  • 1,055
  • 2
  • 9
  • 15
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.

gchfeng
  • 28
  • 4
  • 1
    i suppose it switch off husky hook, similar to remove hooks from .git folder. this way just bypass the problem but not solving it – Artem Vertiy May 05 '22 at 20:16
  • @ArtemVertiy Husky no longer supports precommit hooks in package.json, hooks are defined in .husky folder – Spock Mar 05 '23 at 17:03
0

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

My solution:

npm i -D  prettier@2.8.8
Amir
  • 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](/help/how-to-answer). – Community Aug 29 '23 at 08:00
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

HackerMF
  • 475
  • 7
  • 18