Bulk Updating Author in Git

Update 2012-12-29: My Updating the first commit in a git repo outlines how to update author information for all commits, including the repo’s first commit.

My friend Andrew says if you need to do something more than twice manually, time to automate.

On a remote machine I had a bunch of commits I needed to reel into the main repository. The author information was not set on that machine, so I ended up with commits that looked similar to:

commit 6347180d7ada6f198af949375e2e1e1d6692a215 (HEAD, transxml_tools)
Author: user <user@ws-trans02.(none)>
Date: Fri Aug 5 09:48:21 2011 -0700

The author information for a single commit can be fixed by using the command:

git commit --amend -C HEAD --author='My Name <my@name.com>'

Using git rebase --interactive it’s possible to do this for multiple commits, but you still have to deal with manually editing git’s “command buffer” and then running git rebase --continue after updating each revision. But UNIX is cool and it’s possible to curb CTS with two commands.

First, use GIT_EDITOR and sed to automate editing the command buffer:

GIT_EDITOR="sed -i -e 's/^pick/edit/'" git rebase -i <your base ref>

This changes all pick commits to edit commits, which tells git rebase to stop at all commits giving you the chance to change it. Make sure to change <your base ref> with the base commit you want to rebase from, e.g. origin/master

Then run the git commit command above until git rebase --continue errors out:

while [ 1 ]; do git commit --amend -C HEAD --author='My Name ' && git rebase --continue || break; done;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s