Victus Spiritus

home

A gift to future me, git rename user in old commits

23 Feb 2012

Say goodbye to old crufty commits from unknown@localmachine


#!/bin/sh

git filter-branch --env-filter '
if [ "$GIT_COMMITTER_NAME" = "unknown" ];
then
export GIT_COMMITTER_NAME="user";
export GIT_COMMITTER_EMAIL="user@email.com";
fi
if [ "$GIT_AUTHOR_NAME" = "unknown" ];
then
export GIT_AUTHOR_NAME="user";
export GIT_AUTHOR_EMAIL="user@email.com";
fi'

Thanks to StackOverflow for leading me to a solution to the historical commit username swap.

If you mess up your git_rename.sh don't forget this panic button:
git reset --hard refs/original/refs/heads/master