Combine the first two commits of a Git repository?

Christian picture Christian · Jan 12, 2009 · Viewed 45.7k times · Source

Suppose you have a history containing the three commits A, B and C:

A-B-C

I would like to combine the two commits A and B to one commit AB:

AB-C

I tried

git rebase -i A

which opens up my editor with the following contents:

pick e97a17b B
pick asd314f C

I change this to

squash e97a17b B
pick asd314f C

Then Git 1.6.0.4 says:

Cannot 'squash' without a previous commit

Is there a way or is this just impossible?

Answer

kostmo picture kostmo · Feb 9, 2014

Use git rebase -i --root as of Git version 1.7.12.

In the interactive rebase file, change the second line of commit B to squash and leave the other lines at pick:

pick f4202da A
squash bea708e B
pick a8c6abc C

This will combine the two commits A and B to one commit AB.

Found in this answer.