Updating the first commit in a git repo

I started a git repo in a VM without configuring an author and wanted to update all the commits, including the first one, which is a bit elusive.

The StackOverflow post Change first commit of project with git? almost nails it. For my use-case, or git version, I found Step 4 to be slightly incorrect. It states to use <commit after changed>, but I got it to work with the same hash used in Step 2. For example, say you are on the master branch and you want to update the author information for the first commit:


$ git checkout -b rename
$ first_commit=$(git rev-list HEAD | tail -n 1)
$ git reset --hard ${first_commit}
$ git commit --amend --author "Roberto Aguilar " -C HEAD
$ git rebase --onto rename ${first_commit} master

Now that the first commit is correct, I use the trick outlined in my Bulk Updating Author in Git to finish up the job:


$ new_first_commit=$(git rev-list HEAD | tail -n 1)
$ GIT_EDITOR="sed -i -e 's/^pick/edit/'" git rebase -i ${new_first_commit}
$ while [ 1 ]; do git commit --amend -C HEAD --author='Roberto Aguilar <roberto@baremetal.io' && git rebase --continue || break; done;

Advertisements

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