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 <email@example.com>'
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.
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;