Last active
June 23, 2016 18:40
-
-
Save yogsototh/0f0fae6c1f9c6e2afbbb6e467d9e07a0 to your computer and use it in GitHub Desktop.
enforce commit message to start with issue number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This file should be in .git/hooks/commit-msg | |
# It uses the current branch name to prefix the commit message. | |
name=$(git rev-parse --abbrev-ref HEAD | sed 's/\(issue-[0-9]*\).*/\1/') | |
if [ $name != 'HEAD' ]; then | |
cat $1 | sed "s/^$name: //" | egrep -v "^#" > $1.tmp | |
echo -n "$name"': ' > $1 | |
cat $1.tmp >> $1 | |
rm $1.tmp | |
fi |
Very nice, thanks!
you're welcome! I've updated it again since there was a bug with multiline comments.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy this file in your
.git/hooks/
it will prepend the branch name to your commit messages.If your branch is named
issue-451-something-else
it will only prependissue-451
.It works nicely with amending commit. During rebasing it doesn't prepend anything as during rebasing it is not possible to determine which is the current branch.