To append a paragraph containing just the ticket number to the message of every commit in your repo, install git-filter-repo, then run this in a clone of your repository:
git filter-repo --message-callback 'return message + b"\n\nTIX-321"'
This will, for example, change this commit message:
OBS-12: fix frobulator parsing
Make the parser able to handle the non-numeric IDs returned by the Zob API.
To this:
OBS-12: fix frobulator parsing
Make the parser able to handle the non-numeric IDs returned by the Zob API.
TIX-321
Why these arguments for git filter-repo
The --message-callback flag takes a string that will be interpreted as Python that returns the new commit message given a message bytestring. The callbacks above concatenate the message bytestring and another bytestring. (In Python, you will get an error if you try to concatenate a bytestring b"…" and a string "…".)
--message-callback can easily handle multi-line commit messages, unlike --replace-message. --replace-message takes the path to a file with expressions, but a regex: expression in that file can only return a string based on each line of the commit message. --message-callback can examine and edit the whole commit message.
Examples of other commit message templates
Add the ticket to the beginning of every message
git filter-repo --message-callback 'return b"TIX-321: " + message'
Changes this commit message:
Fix frobulator parsing
Make the parser able to handle the non-numeric IDs returned by the Zob API.
To this:
TIX-321: Fix frobulator parsing
Make the parser able to handle the non-numeric IDs returned by the Zob API.
Leave the message unchanged if the ticket number is already mentioned
git filter-repo --message-callback 'return message if "TIX-321" in message else message + b"\n\nTIX-321"'
Will not modify this commit message:
TIX-321: fix frobulator parsing
Make the parser able to handle the non-numeric IDs returned by the Zob API.