husky: commitizen does not work with 5.0.9
Hi guys,
Husky Version 5 breaks the pre-commit-message hook for Commitizen.
I think this is a common problem for Husky V5 migration.
(If like me you are used to simply adding husky and commitizen to a project without knowing of the changes in new Husky 5, then this may save you time.)
SOLUTION (1) - Husky v4:
STEP 1: Roll back to Husky 4.3.8
SOLUTION (2) - Husky v5:
STEP 1: Replace the following hook in package.json:
( This is the Husky Version 4 hook specified by commitizen, see: https://github.com/commitizen/cz-cli )
"husky": {
"hooks": {
"prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
}
},
STEP 2: With a external hook by executing the following (which create a Husky V5 hook in a separate file):
npx husky add .husky/prepare-commit-msg "exec < /dev/tty && git cz --hook || true"
You hook will be output here:
.husky/prepare-commit-msg
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 17 (4 by maintainers)
@lucaslamar you won’t be able to surpress default behavior of
git commitwith the comand of yours (if no message is provided, git will open a default editor to let you type a message - in your case it is nano)Use the answer above by @ricovilela to trigger commitizen on git commit
However, if you have only the prepare-commit-msg hook set up, I advise you to use
yarn czcommand directly. Otherwise there will be always a step, where your default editor for your OS opens right after commitizen finishes, because that’s how this hook works.I need to migrate from version 4 to 6, I ran the commands and put
but when executing the command
git commitit happened@ahutchings @azu @alexeyten
I was able to resolve this by running the
husky-4-to-5migration tool in an existing project (encouraged by the husky migration docs), which basically performs the steps described by @paulmboyce . It copied over my hooks from thehuskysection ofpackage.jsoninto applicable files in.husky, so the section inpackage.jsonis no longer needed.I avoided the global install and got this working by switching
git cztonpx czin theprepare-commit-msghook:Specs
husky4.3.8->5.1.1commitizen4.2.3cz-emoji1.3.1Working on Windows 10 and WSL Ubuntu
20.04someone has version 7.0.1? I’m having the same problem with @lucaslamar My interactive terminal opens. ask the questions. but instead of committing at the end it opens the text editor. my hook file is the same as what @zorgick put above.
I have the same problem 🥲, is there any solution better then
alias commit with a default message, I think it’s a hack.And after add the hook, run
npx czwill call cz twice.@miguelsmuller It is unclear what you want to achieve. If you want to add an alias for
git commit -m 'a'in a single repo, execute this command in your repo:This will create an alias in ./.git/config, that will work only in this repo
Just wanna point out that
npx czis a similar workaround to installinggit-czlocally for a project. Neither of which should need to happen.