Dan Poltawski's blog

Rewriting history with git

On my home laptop I use git for personal projects and company projects, when using git I try to use the appropriate email address for task. [1]

On a project I was working on today I managed to forget to do this and made 20 commits in the wrong email address. Git is an incredibly versitile tool and I frequently find i’m restricted not by what it can do, but my knowledge of the tool which will help me! In this case it was git-filter-branch, which lets you rewrite history, in seconds.

I used the following to rewrite my email address from work to my personal email address

git-filter-branch --env-filter \
'if [ "$GIT_AUTHOR_EMAIL" = "dan@work" ];
then
export GIT_AUTHOR_EMAIL="dan@personal"
fi'

Edit: I forgot about the git committer field though, doh!

[1] Easily achieved by setting my work email in the global .gitconfig and per-repoistory config overrides for exceptions on personal projects (in the minority)