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

Viewed 98245

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

enter image description here

I don't know what I am doing wrong. I tried git clean command too. Anyone faced similar issue?

6 Answers

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

#Solution 1:

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.

#Solution 2:

this is a temporary/quick solution

git commit -m "message" --no-verify

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.

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"
  }
}

I find two temporary solution like that

git config --unset core.hooksPath  

or

git commit -m "message" --no-verify 

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.

For me I had to add

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

to my package.json

Related