Rebasing a git history with empty commit messages

As I commented before, this totally destroys comments if you happen to have newlines in them. Here's a perl script that does this without being destructive:

#!/usr/bin/perl

my $data = "";    
while(<STDIN>) {
    $data .= $_;
}

if($data =~ /^\s*$/) { $data="[Empty message]\n"; }
print "$data";

Then, just git filter-branch -f --msg-filter /path/to/perlfilter.pl


To replace empty commit messages with some template, you can do something like this:

git filter-branch -f --msg-filter '
read msg
if [ -n "$msg" ] ; then
    echo "$msg"
else
    echo "The commit message was empty"
fi'

Tags:

Git