And now I'm on my computer, here is the modified version. Put this in:
.git/hooks/prepare-commit-msg
#!/usr/bin/env bash
BRANCH=$(git symbolic-ref --short HEAD 2> /dev/null)
# fail gracefully if we don't have a branch
if [ -z "$BRANCH" ]; then
exit 0
fi
# add a git trailer with the branch
git interpret-trailers --in-place --where before --if-exists addIfDifferent --trailer Branch="$BRANCH" "$1"
And if you add the following alias to your ~/.gitconfig you'll be able to see the branch names in the logs by typing git lb (for log branch):
I'm thinking of writing a commit hook to make sure that every commit has the following metadata in trailers:
- original parent commit
Between this and the synopsis it
should then be possible to find all
evolutions of this commit.
- original upstream URI and branch (if
known) or upstream URI and branch
targeted for integration (prompting
if necessary)
- commit type and optional tracker ID
When a commit has these metadata already, leave it.
.git/hooks/prepare-commit-msg
And if you add the following alias to your ~/.gitconfig you'll be able to see the branch names in the logs by typing git lb (for log branch):