We prefix all git commits with ticket numbers. Sometimes I need to batch rename the ticket number for a range of commits. For example, I want to rename change all JIRA-1111
occurrences in commit messages to JIRA-2222
in all commits from between origin/master
and master
. So this git history:
* JIRA-1111 commit message 5 (master)
* JIRA-1111 commit message 4
* JIRA-42 commit message 3
* JIRA-2222 commit message 2
* JIRA-1111 commit message 1 (origin/master)
would be changed to:
* JIRA-2222 commit message 5 (master) # <- renamed from 1111 to 2222
* JIRA-2222 commit message 4 # <- renamed from 1111 to 2222
* JIRA-42 commit message 3
* JIRA-2222 commit message 2
* JIRA-1111 commit message 1 (origin/master)
I know how to change the commit messages for individual commits using either --amend
, or interactive rebase and editing each commit message manually. But my question is:
How can I modify the commit message for a range of commits in batch without manually editing each commit message?
(If you wonder why I need this: The commit dialog in IntelliJ IDEA shows the last commit message which contains the ticket number I'm working on. But sometimes (if not all files are committed), it doesn't remember the last message and shows an older one. When this older message contains a different ticket number, we often end up committing under the wrong ticket number.)