git-filter-branch can do what you want. In particular, you need the --msg-filter argument:
This is a filter for overwriting commit messages. The argument is evaluated in a shell with an initial commit message on standard input; its standard output is used as a new commit message.
One wrinkle is that git-filter-branch wants to run each commit in the branch, while you only want to rewrite one commit (and then effectively recompose the rest). Thus, your message filter must have some conditional logic in order to display either a new commit comment (for the one you really want to rewrite) or the original unmodified commit message (for everything else).
This is the trick:
git filter-branch --msg-filter "ruby /path/to/filter.rb 843c2da5e07de914ea2319fa3295730ff8b3b0a1 'New message'" HEAD
git-filter-branch modifies the current directory before it calls your script, so you need to fully qualify /path/to/filter.rb .
Here filter.rb :
if ENV['GIT_COMMIT'] == ARGV[0] puts ARGV[1] else puts STDIN.read end
Most likely, this could be rewritten in more detail in the script shell, perhaps without even putting the script message filter in a separate file; but I work on Windows, so I donβt have anything like that. I have Ruby, so I used this and it works.
source share