Using external information in the commit message
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 review the commit message by machine to check whether it has a specific format.
In this recipe, we will be manipulating and checking the content of a commit message.
Getting ready
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 ...
Get Git: Mastering Version Control now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.