Skip to content

Instantly share code, notes, and snippets.

@goodevilgenius
Last active October 26, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goodevilgenius/f0c8d3f8469f89a7ee0f to your computer and use it in GitHub Desktop.
Save goodevilgenius/f0c8d3f8469f89a7ee0f to your computer and use it in GitHub Desktop.
[git commit message] This git hook can be used to enforce a format for git commits, according to this suggestion on StackExchange: http://programmers.stackexchange.com/a/112710 #development #git
#!/bin/bash
# This requires the commit summary to start like this:
# [XXX]: message
# * Add
# * Mod(ify)
# * Ref(actor)
# * Fix
# * Rem(ove)
# * Rea(dability)
# Save to .git/hooks/commit-msg and chmod +x it.
# Save gitmessage.txt to ~/.gitmessage and run:
# git config --global commit.template ~/.gitmessage
# This will remind you to use the correct format when committing
totallines=$(wc -l "$1" | awk '{print $1}')
let l=1
summary="$(sed -n '/^[^#]/{p;q}' "$1")"
echo "$summary" | egrep -i '^\[(Add|Mod|Ref|Fix|Rem|Rea)\]' >/dev/null
if [ $? -ne 0 ]
then
echo "Status line must start with [XXX] where XXX is a valid commit type" >&2
echo "Commit aborted. Try again" >&2
exit 1
fi
exit 0
[XXX]: summary
More details
* Step 1
* Step 2
# Use one of the following in [XXX]:
# * Add
# * Mod(ify)
# * Ref(actor)
# * Fix
# * Rem(ove)
# * Rea(dability)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment