How to change the specific string throughout all git message commits?

git, git-rewrite-history, github, rebase, version-control

Solution

Use `git-filter-branch` with it's `--msg-filter` option, e.g.:

git filter-branch -f --msg-filter 'sed "s/git-svn.*$//g"' -- --all

Note that this will change pretty much all your commit ids in your repo, and so everyone who works on your project will thus need to do a fresh clone.

See this blog post for some more discussion:

http://mm0hai.net/blog/2011/03/10/rewriting-git-commit-message-history.html

Note that the above command only executes against your local copy, and you need to push to GitHub in order to get your updates reflected there...

Step-by-step

First clone a fresh copy of your repo, using the `--mirror` flag:

$ git clone --mirror git://example.com/my-repo.git

This is a bare repo, which means your normal files won't be visible, but it is a full copy of the Git database of your repository, and at this point you should make a backup of it to ensure you don't lose anything.

Now you can run `git-filter-branch` to fix your commit messages:

git filter-branch -f --msg-filter 'sed "s/git-svn.*$//g"' -- --all

Once you're happy with the updated state of your repo, push it back up (note that because your clone command used the `--mirror` flag, this push will update all refs on your remote server):

$ git push

At this point, you're ready for everyone- including yourself -to ditch their old copies of the repo and do fresh clones of the nice, new pristine data.

...I'm compelled to point out that The BFG is often much better than `git-filter-branch` for cleaning up Git history, but in this case just `git-filter-branch` sounds perfect for your needs.

Problem

I want to grep and change specific string throughout all messages that are pushed to Github. Is it possible? How? I know how to change last message bye `git commit --amend` but I want to change all message of all commits.

Original source