Created
March 29, 2016 08:32
-
-
Save thoroc/c84eaa9b491dfc975886 to your computer and use it in GitHub Desktop.
How to add Git's branch name to the commit message? http://stackoverflow.com/questions/5894946/how-to-add-gits-branch-name-to-the-commit-message/18739064
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/sh | |
# | |
# Automatically add branch name and branch description to every commit message except merge commit. | |
# | |
COMMIT_EDITMSG=$1 | |
addBranchName() { | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
DESCRIPTION=$(git config branch."$NAME".description) | |
echo "[$NAME]: $(cat $COMMIT_EDITMSG)" > $COMMIT_EDITMSG | |
if [ -n "$DESCRIPTION" ] | |
then | |
echo "" >> $COMMIT_EDITMSG | |
echo $DESCRIPTION >> $COMMIT_EDITMSG | |
fi | |
} | |
MERGE=$(cat $COMMIT_EDITMSG|grep -i 'merge'|wc -l) | |
if [ $MERGE -eq 0 ] ; then | |
addBranchName | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment