For certain reason, some time you want your commit message to follow a standard pattern.

i.e. PJK-001: my message

Want to have a project code and assignment code there.

Now, open up your project git directory.

i.e. /path/to/your/project/.git/hooks/

and edit commit-msg file (if doesn’t exist, create it)

(NOTE: This example I’ll write in Python)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/python

import sys
import re

message_file = sys.argv[1]
message = open(message_file, 'r').read()

# Match with a specified pattern
match = re.match(r'PJK-(\d+):\ ', message)

if match is None:
print 'Your commit has been rejected!'
print 'Commit message must begin with \'PJK-(\d+): \''
print 'i.e. PJK-12: this is a commit message'
sys.exit(1)

Simple right? But don’t remember to change it to executable and no .py extension

1
$ chmod 755 /path/to/your/project/.git/hooks/commit-msg

References: