Skip to content

Instantly share code, notes, and snippets.

@tscolari
Last active December 20, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tscolari/6079400 to your computer and use it in GitHub Desktop.
Save tscolari/6079400 to your computer and use it in GitHub Desktop.
Commit with story id
  • add prepare-commit-msg it to ./.git/hooks/
  • Make it executable (chmod +x filename)

It should prepend [#STORY_ID] into your commit message when the editor pops up. Your branch must be in this format to work: branch-description-blabla-STORY_ID

it skips the prepaend if:

  • The branch doesn't end in a story id (integer)
  • The original commit message starts with "Merge"
cat $1 | head -n 1 | egrep "Merge" && exit 0
BRANCH=$(git rev-parse --abbrev-ref HEAD)
STORY_ID=$(echo ${BRANCH##*-})
if [[ "$STORY_ID" =~ ^[0-9]+$ ]]
then
original_message=$(cat $1)
echo "[#${STORY_ID}] ${original_message}" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment