If you have to change an old commit message over multiple branches (i.e., the commit with the erroneous message is present in multiple branches) you might want to use
git filter-branch -f --msg-filter 'sed "s/<old message>/<new message>/g"' -- --all
to replace the commit message.
Git will create a temporary directory for rewriting and additionally backup old references in refs/original/.
-f
will enforce the execution of the operation. This is necessary if the the temporary directory is already present or if there are already references stored under refs/original. If that is not the case, you can drop this flag.
--
separates filter-branch options from revision options
--all
will make sure, that all branches and tags are rewritten.
Due to the backup of your old references, you can easily go back to the state before executing the command.
Say, you want to recover your master and access it in branch old_master:
git checkout -b old_master refs/original/refs/heads/master
After you are satisfied with your changes use
git push -f
to push the changes to your public repo.
Note that you should inform your collaborators about this since all the hashes of the commits starting with the first modified one have been changed.