The commit hook is executed when you close the commit message editor. It can, among other things, be used to manipulate the commit message or do an automatic review of the commit message to check whether it has a specific format.
In this recipe, we will be manipulating and checking the content of a commit message.
To start this exercise, we just need to create a branch and check it out. We need to disable the current prepare-commit-msg
hook; we can do this by simply renaming it. Now, we can start working on the commit-msg
hook by using the following command:
$ git checkout -b commit-msg-example
Switched to a new branch 'commit-msg-example'
$ mv .git/hooks/prepare-commit-msg .git/hooks/prepare-commit-msg.example