Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

husky

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?

like image 756
Ben Alan Avatar asked Jul 05 '21 20:07

Ben Alan


People also ask

How do I force an empty commit?

Pushing an empty commit without adding any staged files to the branch is very easy. It is the same as pushing a regular commit, except that all you need to do is add –allow-empty flag to the command line. The commit is now pushed to your branch without any changes.

How do I commit an empty message?

Creating an empty commit is easy. You simply add the --allow-empty flag on git commit command and add your message. Now you can create all the empty commits you want!

What happens if I commit without a message?

Git commit messages are necessary to look back and see the changes made during a particular commit. If everyone will just commit without any message, no one would ever know what changes a developer has done.

What is Commitlint?

Commitlint is a simple tool that lints your commit messages and makes sure they follow a set of rules. It runs as a husky pre-commit hook, that is, it runs before the code is committed and blocks the commit in case it fails the lint checks.


Video Answer


3 Answers

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 !

like image 97
Pierre Carbonnelle Avatar answered Oct 22 '22 00:10

Pierre Carbonnelle


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.

like image 19
Ben Alan Avatar answered Oct 22 '22 00:10

Ben Alan


Another Solution you can try is

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

git commit -n -m "Hello World!"

References

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks

like image 13
Ashish Singh Rawat Avatar answered Oct 21 '22 23:10

Ashish Singh Rawat