Git hook to help you write good commit messages.
Validates commit messages conform to six of the seven rules of a great git commit message, plus a couple of extras:
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
Use the body to explain what and why vs. how- you're on your own with this one- Do no write single worded commits
- Do not start the subject line with whitespace
Offers an interactive prompt if any of the rules are detected to be broken.
At the root of the repository, run:
curl https://cdn.rawgit.com/tommarshall/git-good-commit/v0.6.1/hook.sh > .git/hooks/commit-msg && chmod +x .git/hooks/commit-msg
To use the hook globally, you can use git-init
's template directory:
mkdir -p ~/.git-template/hooks
git config --global init.templatedir '~/.git-template'
curl https://cdn.rawgit.com/tommarshall/git-good-commit/v0.6.1/hook.sh > ~/.git-template/hooks/commit-msg && chmod +x ~/.git-template/hooks/commit-msg
The hook will now be present after any git init
or git clone
. You can safely re-run git init
on any existing repositories to add the hook there.
If you're security conscious, you may be reasonably suspicious of curling executable files. In this case you're on HTTPS throughout, and not piping directly to execution, so you can check contents and the hash against MD5 12fd3b8829eead2eff9a72598cbc9f4b
for v0.6.1.
echo "apple" > ./bar.txt
git add fruits.txt
# should warn you that the subject line is not capitalised, and offer an interactive prompt.
git commit -m 'add fruits.txt'
e - edit commit message
y - proceed with commit
n - abort commit
? - print help
The default colour setting is auto
, but the hook will use git
's color.ui
config setting if defined. You override the colour setting for the hook with:
git config --global hooks.goodcommit.color "never"
Supported values are always
, auto
, never
and false
.
None, other than Bash.
- http://chris.beams.io/posts/git-commit
- http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
- https://www.git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#Commit-Guidelines
- Tim Perry's excellent git-confim hook, which provided the inspiration and much of the scaffolding for this hook.