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

8

63

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?

Moira answered 5/7, 2021 at 20:10 Comment(2)
What it means is that you've added a non-Git program (specifically, something called "husky") and told Git to use Husky to check your commits. Husky did so, Husky found errors, Husky reported those errors, and Git obeyed Husky's result, preventing the commit. Your question is thus entirely about Husky, not Git.Radke
Thank you for the correction. Never heard of husky before :)Moira
G
89

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 !

Gardel answered 27/8, 2021 at 8:21 Comment(2)
Many OSS projects require conventional commit message, it's part of the build and release process and a bunch of that automation relies on the commit messages to perform it's job correctly.Fifine
@BenAlan With a commit convention, packages can be updated automatically and released with their version in the correct stands of SemVer, take a look at this article (it's not mine) platform.deloitte.com.au/articles/…Krouse
P
30

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.

Phosphorus answered 23/11, 2021 at 9:14 Comment(0)
J
29

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?
Jukebox answered 1/2, 2022 at 5:44 Comment(1)
Not exactly what I was looking for but I am satified xDKevinkevina
M
14

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.

Moira answered 5/7, 2021 at 21:10 Comment(2)
You should not unninstall packages if you don't know what it does, in that case, husky grants a convention for commits, pls take a time to read about conventionalcommits.org/en/v1.0.0 And typicode.github.io/husky/#Krouse
This is the most correct answer since you didn’t know what the hooks were doing, or wanted. Git hooks are designed to be installed per repository, not project-wide (security concerns). Dunno how you ended up with Husky, though.Combine
C
1

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.

Cutlery answered 24/5, 2024 at 8:20 Comment(1)
It is not a regex issue, but that is a rule. The specification says "Types other than feat and fix MAY be used in your commit messages, e.g., docs: update ref docs.". Check out the point no 14 here https://www.conventionalcommits.org/en/v1.0.0/#specificationRowdyism
C
1

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"

Cyclothymia answered 29/5, 2024 at 17:7 Comment(0)
A
0

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/#/

Amosamount answered 4/1, 2023 at 6:32 Comment(0)
T
0
$ git commit -m "feat: hello-world-somthing-else"
Tomy answered 22/5, 2023 at 11:59 Comment(2)
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.Bovine
I'm not sure how this could be helpful. It appears to be the exact same syntax as in the question.Airborne

© 2022 - 2025 — McMap. All rights reserved.