What's the fastest way to edit hundreds of Git commit messages?

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.

  • How to use forked git project in Android Studio
  • Git: endless merges. I'm tired of them
  • Which git tool generated this tree view?
  • Private Git on OpenShift
  • git - changes to branch since created?
  • Deploy WAR file to Openshift without using GIT?
  • 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.


  • Git installation issue in Mountain Lion (OS X 10.8)
  • How does GitHub handle push security?
  • How can I visualize per-character differences in a unified diff file?
  • Remove a commit's parent, thereby making it the initial commit
  • Can I update a forked project, on git, to the original/master copy?
  • Squashing and reorganizing commits
  • 5 Solutions collect form web for “What's the fastest way to edit hundreds of Git commit messages?”

    This is easy to do as follows:

    • Perform first import.
    • 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.

    • Edit these files using some script.
      (Do not touch anything in them except for top with commit messages).
    • Copy or move edited files to empty git repo or branch.
    • Import all edited commits back:

      git am *.patch

    This will work only with single branch, but it works very well.

    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

    A great and simple way to do this would be to use git filter-branch --msg-filter "" with a python script.

    The python script would look something like this:

    import os
    import sys
    import re
    pattern = re.compile("(?i)Issue-\d{1,4}")
    commit_id = os.environ["GIT_COMMIT"]
    message   = sys.stdin.read()
    if len(message) > 0:
        if pattern.search(message):
            message = pattern_conn1.sub("Issue",message)
    print message

    The command line call you would make is git filter-branch -f --msg-filter "python /path/to/git-script.py"

    As alternative, consider skipping the import of the whole repository. I would simply checkout, clean up and commit important points in the history.

    You can use git rebase -i and replace pick with reword (or just r). Then git rebasing stops on every commit giving you a chance to edit the message.

    The only disadvantages are that you don’t see all messages at once and that you can’t go back when you spot an error.

    Git Baby is a git and github fan, let's start git clone.