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.

- 24,513
- 11
- 72
- 101

- 2,769
- 9
- 41
- 66
1 Answers
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.

- 24,513
- 11
- 72
- 101
-
Thank roberto, I have changed all of "is" to "was" in my commit history (My english is too bad :D ). why Github doesn't show the actual strings? see here: https://github.com/khajavi/Design-Patterns/tree/master/Behavioural and here https://github.com/khajavi/Design-Patterns/commits/master/Behavioural compare the. why they are different???! – Milad Khajavi Apr 08 '13 at 08:14
-
@Khajavi that was probably just a browser refresh issue, the commit messages on both pages matched when I checked them just now - for instance, the latest commit message is "Behavioural's readme was added." for both. – Roberto Tyley Apr 08 '13 at 08:44