Commit-editmsg
Electro Sales Corporation / Electro Systems

You want every commit message to follow the Conventional Commits standard (e.g., feat: add login, fix: resolve null pointer).

Your commit-msg hook can read .git/COMMIT_EDITMSG and reject the commit if it doesn't match the regex:

#!/bin/sh
# .git/hooks/commit-msg

message_file=$1 # This is the path to COMMIT-EDITMSG pattern="^(feat|fix|docs|style|refactor|test|chore)((.+))?: .+"

if ! grep -q -E "$pattern" "$message_file"; then echo "ERROR: Commit message does not follow Conventional Commits format." echo "Expected: <type>(<scope>): <subject>" echo "Example: feat(auth): add OAuth2 provider" exit 1 fi

Now, if a developer tries to commit with a bad message, Git aborts. This doesn't just work for command-line commits; it works for GUI tools and IDEs because everything eventually writes to COMMIT-EDITMSG.

Original (poor):

fixed bug in user stuff

Revised (good):

Fix session invalidation after password change

Previously, a user changing their password would remain logged in on other devices. This change explicitly invalidates all active sessions for that user except the current device.

Closes #234


If you paste the actual contents of your COMMIT-EDITMSG, I will give you a line-by-line review with specific corrections.


You can bypass commit-msg hooks with --no-verify:

git commit --no-verify -m "Hotfix for production"

Warning: Use sparingly. This is a nuclear bypass for emergency situations.

Several Git settings control how this file behaves: