evgeniuz
evgeniuz

Reputation: 2769

Commit message prefix in git

I have a requirement to prepend "ticket:N" to commit messages, where N is the number of the ticket I'm working on. But I keep forgetting about the prefix and remember about it only 5-6 commits later, so --amend won't help. Is it possible to set some warning, so git will warn me every time I forget to add the prefix?

Upvotes: 5

Views: 6505

Answers (3)

svick
svick

Reputation: 244757

To make sure every commit message follows some standard form, you can use the commit-msg hook.

But if you want to edit the commit message of some commit that is not the most recent, you can do that too using git rebase -i, assuming you didn't push it yet.

Upvotes: 4

TomDane
TomDane

Reputation: 1066

If you specifically want to add JIRA ticket numbers to your commits you can use this method https://tjdane.medium.com/add-a-jira-ticket-to-a-batch-of-old-commits-67557fb42d3e

Upvotes: 0

felixyadomi
felixyadomi

Reputation: 3396

You can use filter-branch in combo with --msg-filter to update a range of commits.

For example, If you want to prepend ticket:N to every commit message from HEAD to xxxxxx:

git filter-branch -f --msg-filter 'printf "ticket:N " && cat' xxxxxx..HEAD

You can also append to the commit message by simply reversing printf and cat:

git filter-branch -f --msg-filter 'cat && printf "ticket:N"' xxxxxx..HEAD

Upvotes: 4

Related Questions