Ben Alan
Ben Alan

Reputation: 1695

Strange error when attempting to commit. [subject-empty]

I type this into the CLI

git commit -m "Hello World!"

This is the error message I get

husky > commit-msg (node v14.15.3)
⧗   input: Hello World!
✖   subject may not be empty [subject-empty]
✖   type may not be empty [type-empty]

✖   found 2 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

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

What does this mean?

Upvotes: 71

Views: 108059

Answers (8)

ruby_newbie
ruby_newbie

Reputation: 3285

I got this error on a project that uses conventional commits and my problem was a leading space in the commit message. As an example:

Incorrect: " Hello world"

Correct: "Hello world"

Upvotes: 1

JJ Du Plessis
JJ Du Plessis

Reputation: 1139

This has been annoying the heck out of me for a few weeks now. Sometimes it works, sometimes it doesn't.

Here's what I finally figured out: don't use fix, feat, chore, docs, etc. in your actual description part of the message.

Examples:

Wrong fix(something): Fixed the thing

Right fix(something): Unborked the thing

Seems their regex sucks.

Upvotes: 2

Pierre Carbonnelle
Pierre Carbonnelle

Reputation: 2625

To fix the error, change your commit message ("Hello world") to follow the Conventional Commits format, e.g. to "feat: hello world".

As the "Get Help" message link (in your error message) explains, husky calls commitlint to verify that your commit message conforms to this format.

We should always RTFEM !

Upvotes: 97

Mr.Sharp
Mr.Sharp

Reputation: 224

$ git commit -m "feat: hello-world-somthing-else"

Upvotes: 0

Ashish Singh Rawat
Ashish Singh Rawat

Reputation: 1593

Another Solution you can try is

git commit --no-verify -m "Hello World!"

git commit -n -m "Hello World!"

References

  1. Git hooks (https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks)
  2. check for conventional commit.
  3. What is commit lint and setting up?

Upvotes: 32

Catherine R
Catherine R

Reputation: 1

As you installed husky it checks when you commit or push the code in to your github repo. I guess you have installed the commitlint and used it in your .husky precommit file . If so you have to follow the commitlint rules before every commit like "fix: bug-fixes" .

refer:https://commitlint.js.org/#/

Upvotes: 0

Ben Alan
Ben Alan

Reputation: 1695

I fixed this problem with "npm uninstall husky"

edit: make sure you know what it does and that your project doesn't use it before you remove it.

Upvotes: 14

GoTo
GoTo

Reputation: 6726

For me it was a space. Changed

`feat(pill):message here` 

to

`feat(pill): message here`

There is a package called husky that defines a certain template for your commit messages. If the template is not fulfilled, one gets strange errors.

Upvotes: 35

Related Questions