Home > other >  Append ticket number to all commit messages in git history local and remote
Append ticket number to all commit messages in git history local and remote

Time:10-06

How could I append the ticket number "TIX-321" to all commit messages already existing in my branch test_branch, within a bash script?

It would amount to looping thru all commits and for each git amend commit.

I would like to do it automatically within a shell script, I do not want to do it manually with an interactive rebase.

CodePudding user response:

You could do an interractive rebase of your branch (assuming it comes from main)

git switch test_branch
git rebase -i $(git merge-base --fork-point main)

In the editor automatically opened, you can then change all commit messages, save and quit.
That will rewrite each commit of your branch, which you will have to force push (make sure anyone working on that branch is aware).

You can use the same range of commits to do so programmatically, using git filter-repo, using its new --replace-message option.
As with replace-text, regex: is supported, so you can use an expression.txt file with:

regex:(.*)$==>TIX-321 \1

And the command:

git filter-repo --replace-message expressions.txt $(git merge-base --fork-point main)..test_branch
  • Related