3

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.

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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: github.com/khajavi/Design-Patterns/tree/master/Behavioural and here github.com/khajavi/Design-Patterns/commits/master/Behavioural compare the. why they are different???!
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.