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
- I used the option
--msg-filter
to edit only the commit message but you can use other filters to change files, edit full commit infos, etc.
- I limited
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…