3 ms·
I have a git commit hook that automatically adds a git trailer containing the jira ticket/issue number to the commit message. It gets this from the branch name
by imron 2y ago
I have a git commit hook that automatically adds a git trailer containing the jira ticket/issue number to the commit message.
It gets this from the branch name which by my convention always contains the ticket ref.
It would be trivial to modify this to use the full branch name instead.
- imron 2y agoAnd 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): [alias] lb = log --color --graph --pretty=format:'%Cred%h%Creset %C(bold)%(trailers:key=Branch,valueonly,separator=%x2c)%Creset - %s %Cgreen(%cr)%C(bold blue) <%an>%C(nobold yellow)%d%Creset' --abbrev-commit
- cryptonector 2y agoI'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.