Before users push their commits, I'd like to pre-pend the branch name to the commit message. Is this possible?
If it is, would I use the git commit --amend
command?
Our branch names contain the ticket number and its important to see this info when its merged into master and in Jenkins. To see it easily, it must be the first line in the commit message. To ensure the fist line is the branch name (containing the ticket number), I'd like to use the pre-push hook. I could use other hooks, such as prepare-commit-message
or use a message template but that puts the branch name on every commit, and it doesn't ensure that the branch name is there after a rebase. Using the pre-push ensures the branch name is there before it goes into the remote.
=============
update: Yes, it is possible but its a bad idea.
The pre-push hook syncs the refs with the remote before running but before any objects are pushed. This means the remote already has the commit sha set for the change you are pushing. When the pre-push
hook ammends the commit message a new sha is generated, putting you immediately out of sync with the remote.