Aug 19, 2008
I recently needed to rewrite history of commits in a private
Git repository, because I wanted to change my email address in every commit. Note that you should not try following tip in a repository that anyone has pulled from. Normally Git doesn't allow you to do this kind of thing, since changing authorship is...well bad (usually also against the law).
Let's assume that email address changed from firstname.lastname@example.org to email@example.com. To create copy of repository
$PROJECT_DIRto new repository
$NEW_REPOwith changed emails we can do following:
$ cd $PROJECT_DIR # change to project repository
$ git fast-export --all > /tmp/project.git # export repository to temporary file
$ sed 's/^author\(.*\)<firstname.lastname@example.org>/author\1<email@example.com>/' /tmp/project.git # replace emails on every line starting with 'author'
$ cd $NEW_REPO # change to empty directory
$ git init # initialize git
$ git fast-import < /tmp/project.git # import modified repository
Third step is potentially dangerous, because you have to make sure that you don't edit contents of any file aside from metadata. If you change content of files, git fast-import will complain because sha1 hash will not be correct.
Be sure to read
git fast-exportman pages for additional information. It took me a while playing with git-rebase and similar stuff to realize that they do not offer such feature, so if this tip helps anyone else I'll be glad.