How do I git rebase the first commit?

lxs picture lxs · Apr 10, 2014 · Viewed 29.4k times · Source

I used git init to create a fresh repo, then made three commits. Now I want to rebase to go back and amend my first commit, but if I do git rebase -i HEAD~3 it complains! If I try the same with HEAD~2 then it kinda works but only lets me rearrange the last two commits.

How do I refer to the 'commit before there were any commits' or go back and insert an empty commit?

Answer

torek picture torek · Apr 11, 2014

The easy way, with a recent-enough git (this has been out for a long time now so you should have this):

git rebase -i --root

The other easy way, as twalberg noted in a comment, is to use git checkout --orphan to set up to make a new root commit, which you can copy the old commits on top of. (This is what rebase -i --root ends up doing internally anyway.)