After converting a Git repository from Subversion with svn2git, all was well. At least until I wanted to squash some of the oldest commits with the excellent interactive rebase. Full of fail, I realized that I might have to do some cleanup before going on such a bold expedition. Here's a couple tricks for "post-processing" a converted repository.

  1. Make a backup! Ideally, do this work on a clone of the original repository, then use a tool like Meld (or simply diff -r repo_backup new_repo) to check that the resulting files are the same as before.
  2. Remove empty commits: git filter-branch --commit-filter 'if [ z$1 = z`git rev-parse $3^{tree}` ]; then skip_commit "$@"; else git commit-tree "$@"; fi' "$@"
  3. Garbage collect and prune: git gc --prune
  4. Start interactive rebase from the first commit: git rebase -i $(git log --format=%H | tail -1)
  5. Squash all commits with empty messages. These are shown as multiple commit IDs on the same line with a space and > between them, like this:
    pick 1111111 >2222222 >3333333 Message

    Just split these up and remove the commits, like this:

    fixup 1111111 nothing
    fixup 2222222 nothing
    pick 3333333 Message

    In Vim, you can do this by repeating the following command until it reports no hits: :%s/^pick \([a-f0-9]\{7\}\) >\([a-f0-9]\{7\}\)/fixup \1 nothing\rpick \2/g

  6. Exit the editor, and the rebase should complete on its own.

Warning, as always: YMMV and RTFM.