Git - Validate commit message - git hooks
enforce commit messages in git repo
To enforce commit messages in git repo to follow specific format or pattern. This can be achieve by using git-hooks
, where the commit message is formatted with the help of commit-msg
hook. commit-msg hook will be trigger on each commit.
First go to git repo which needs the validator, then create commit-msg
hook file in .git/hooks
folder
|
|
Modify permission to make the hook executable
|
|
Open commit-msg
file in a editor and add the following lines of script.
|
|
Create hook installer
A simple hook installer can be created as follows, here I have used quite a complex pattern.
Customize the $regex
found in the script as per need. Existing regex is designed to handle PROJECT-#### [committer_name_1|committer_name_2] commit message
pattern, which can be replaced.
To install commit-msg-validator.sh
use the following commands
|
|
Hola, commit message validator would be installed successfully.