Alex Rivera | Logout

Change first commit of project with Git?

Asked 2010-02-11T17:17:53.490
662

I want to change something in the first commit of my project with out losing all subsequent commits. Is there any way to do this?

I accidentally listed my raw email in a comment within the source code, and I'd like to change it as I'm getting spammed from bots indexing GitHub.

Edit
Report

1 Answer

998

As mentioned by ecdpalma below, git 1.7.12+ (August 2012) has enhanced the option --root for git rebase:

"git rebase [-i] --root $tip" can now be used to rewrite all the history leading to "$tip" down to the root commit.

That new behavior was initially discussed here:

I personally think "git rebase -i --root" should be made to just work without requiring "--onto" and let you "edit" even the first one in the history.
It is understandable that nobody bothered, as people are a lot less often rewriting near the very beginning of the history than otherwise.

The patch followed.


(original answer, February 2010)

As mentioned in the Git FAQ (and this SO question), the idea is:

  1. Create new temporary branch

  2. Rewind it to the commit you want to change using git reset --hard

  3. Change that commit (it would be top of current HEAD, and you can modify the content of any file)

  4. Rebase branch on top of changed commit, using:

     git rebase --onto <tmp bra
answered 2010-02-22T07:20:36.677

Your Answer