Search code examples
gitcommit

Change old commit messages in Git


I have to replace a text with another one in all the git repo commit messages. It seems to be possible with git rebase -i ... that opens a text editor but I have to do it automatically. Is it doable with some of the git commands or maybe with a Java library?


Solution

  • git filter-branch is the tool to use for automatic bulk history rewriting.

    Specifically --msg-filter:

    --msg-filter This is the filter for rewriting the commit messages. The argument is evaluated in the shell with the original commit message on standard input; its standard output is used as the new commit message.

    In your case, a simple sed as the command might suffice.