Skip to content

3. Git Commit Template

mpc edited this page May 12, 2017 · 2 revisions

Having a git template will aid in making standardized commit messages. Copy and save the following template onto your local computer. For instance, on a Mac, a common location to save in, is ~/.git_template. As long as the location and filename match what you have when you run the git config statement, described below, the template will be utilized during your commit.

# <type>(<Project Prefix><ticket #>):
#
# If applied, this commit will...
#
# <body>
#
# Explain why this change needed to be made
#
# <footer>
#
# ** TYPES **
# feat (new feature)
# fix (bug fix)
# docs (changes to documentation)
# style (formatting, missing semi colons, etc; no code change)
# refactor (refactoring production code)
# test (adding missing tests, refactoring tests; no production code change)
# chore (updating grunt tasks etc; no production code change)
#
# ** FOOTERS **
# References #1, #4, and #2.
# Fix #1. note this marks the item as accepted
# Closes #1 and #2. note this marks the item as accepted

Once the file is saved, issue the following command from the terminal or command line:

git config --global init.templatedir '~/.git_template'

That will setup your global commit template that will be used when you issue a git commit from the command line or from SourceTree. It will bring up your default editor and let you fill in the relevant information.

Git will ignore any line that begins with a hash (#) and will not add those lines to the commit message. Not every section will necessarily be filled in for each commit. For instance, if it's a new feature, the section explaining why the change needs to be made may or may not be relevant.

Limitation

SourceTree will recognize the git template for the Mac version only. This feature is not available on SourceTree for Windows. It is recognized from the command line of both Mac and Windows.

Example

#<type>(<Project Prefix><ticket #>):
feat HH04-login

#If applied, this commit will...
Add the validation for login credentials

# <body>
This will handle all the validation for login, including checking for valid username
and password per the specication (see Section 3.2).  A REST call will be made and it
will return whether the authentication passed or failed.

#
# Explain why this change needed to be made
#