I find that being able to specify the commit message in one go, tricks me into writing short one line commit messages. I often end up along the lines of git commit -m "fix things"
. But whenever I leave off the -m
option, and my editor pops up, I'm more likely to write a good commit message.
In the past I've created habits by disabling features I didn't want to use anymore. As example: I disabled the arrow keys in vim, which finally made me use hjkl. This was so effective, I want to try to do the same for the git commit messages. I want git (or bash or zsh) to yell at me for trying to use commit -m
.
I could write a wrapper around the git command entirely, but maybe you have other solutions and I might learn something cool! I'm open to all sorts of magic and trickery.
git exit commit message After writing commit message, just press Esc Button and then write :wq or :wq! and then Enter to close the unix file.
If an empty message is specified with the option -m of git commit then the editor is started. That's unexpected and unnecessary. Instead of using the length of the message string for checking if the user specified one, directly remember if the option -m was given.
Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.
You can create a prepare-commit-msg
hook in your .git/hooks
directory to check the length of the message and reject the commit if the message is too short:
#!/bin/bash
# Remove whitespace, at least 50 characters should remain.
if (( $(sed 's/\s//g' "$1" | wc -c) < 50 )) ; then
echo Message too short. >&2
exit 1
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With