How to disable the ability to install git commit messages from the command line?

I find that, being able to specify a commit message at a time, I try to write short messages with one line. I often end the line git commit -m "fix things" . But whenever I leave the -m option and my editor appears, I will probably write a good commit message.

In the past, I created habits by disabling features that I no longer wanted to use. As an example: I turned off the arrow keys in vim, which finally made me use hjkl. It was so effective, I want to try to do the same for 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 completely, but maybe you have other solutions, and I could learn something cool! I am open to all kinds of magic and deception.

+7
git bash zsh
source share
1 answer

You can create a prepare-commit-msg binding in the .git/hooks directory to check the message length 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 
+6
source share

All Articles