I have a fairly large Git repository with 1000s of commits, originally imported from SVN. Before I make my repo public, I'd like to clean up a few hundred commit messages that don't make sense in my new repo, as well as to remove all that git-svn informational text that got added.
I know that I can use 'git rebase -i' and then 'git commit --amend' to edit each individual commit message, but with hundreds of messages to be edited, that's a huge pain in the you-know-what.
Is there any faster way to edit all of these commit messages? Ideally I'd have every commit message listed in a single file where I could edit them all in one place.
Thanks!
That's an old question but as there is no mention of git filter-branch
, I just add my two cents.
I recently had to mass-replace text in commit message, replacing a block of text by another without changing the rest of the commit messages. For instance, I had to replace Refs: #xxxxx with Refs: #22917.
I used git filter-branch
like this
git filter-branch --msg-filter 'sed "s/Refs: #xxxxx/Refs: #22917/g"' master..my_branch
--msg-filter
to edit only the commit message but you can use other filters to change files, edit full commit infos, etc.filter-branch
by applying it only to the commits that were not in master (master..my_branch
) but you can apply it on your whole branch by omitting the range of commits.As suggested in the doc, try this on a copy of your branch. Hope that helps.
Sources used for the answer
This is easy to do as follows:
Export all commits into text:
git format-patch -10000
Number should be more than total commits. This will create lots of files named NNNNN-commit-description.patch
.
Import all edited commits back:
git am *.patch
This will work only with single branch, but it works very well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With