Last active
December 17, 2015 17:43
-
-
Save lrobeson/ca66c2614cb76147558f to your computer and use it in GitHub Desktop.
Prepend ticket number to Git commit message
This file contains hidden or 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 | |
| # | |
| # A hook script to prepare the commit log message. | |
| # | |
| # This example prepends the ticket number (read from the feature branch name) | |
| # and formats it according to F1 Git standards. | |
| # | |
| # To use: | |
| # Make a copy of .git/hooks/prepare-commit-msg.sample in your repo and name the file prepare-commit-msg (remove "sample" extension) | |
| # Paste the following into the file, save the file, and try it out. | |
| # | |
| # Notes: | |
| # This borks a little when you're on a non-feature branch like Master, but 95% of the time it helps. :) | |
| # This file has to be included in each Git repository, unfortunately it can't be made a global setting. | |
| # | |
| # More info and examples: | |
| # http://www.tilcode.com/git-how-to-automatically-add-the-branch-name-to-the-end-of-every-commit-message/ | |
| branch=$(git symbolic-ref --short HEAD) | |
| issue=$(echo $branch | sed -e 's/[^0-9]//g') | |
| sed -i.bak -e "1s/^/[#$issue] /" $1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment