Skip to content

Instantly share code, notes, and snippets.

@bracke
Last active December 20, 2015 20:19
Show Gist options
  • Save bracke/6189629 to your computer and use it in GitHub Desktop.
Save bracke/6189629 to your computer and use it in GitHub Desktop.
Git hook: prepare-commit-msg
#!/bin/sh
#
# Based on http://blog.bartoszmajsak.com/blog/2012/11/07/lazy-developers-toolbox-number-1-prepend-git-commit-messages/
#
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
echo "[$BRANCH_NAME] $(cat $1)" > $1
fi
#
# Based on David Winterbottoms prepare-commit-msg
# http://codeinthehole.com/writing/enhancing-your-git-commit-editor/
#
echo "# Last 5 commit messages" >> $1
echo "# ----------------------" >> $1
COMMITS=`git log --pretty=format:"# %h %s [%an]" -5`
echo "${COMMITS}" >> $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment