user784637
user784637

Reputation: 16102

When trying to rebase why is the proposed commit history wildly out of order?

Here is my commit history:

0fb5310 me     Mon Jan 6 08:33:57 2014 -0500   four
f407eac me     Mon Jan 6 08:32:34 2014 -0500   three
c8ede60 me     Mon Jan 6 08:31:49 2014 -0500   two
06dd7e9 me     Mon Jan 6 08:30:04 2014 -0500   one
026cb0d me     Mon Jan 6 04:21:57 2014 -0800   Initial commit

I want to squash the entire commit history except for the most recent commit. When I try to do this I get the following error.

$ git rebase -i HEAD~4
fatal: Needed a single revision
invalid upstream HEAD~4

Why can I not rebase up to the first commit?

When I do

$ git rebase -i HEAD~3

Why is the interactive proposed history wildly out of order HEAD~2->HEAD~4->HEAD~0?

Why does it not show all 4 commits (HEAD~0, HEAD~1, HEAD~2, HEAD~3) ?

pick c8ede60 two
pick 026cb0d Initial commit
pick 0fb5310 four

Also why does $ git rev-parse HEAD~4 result an in error fatal: ambiguous argumentHEAD~4: unknown revision or path not in the working tree while the interactive prompt for the rebase shows HEAD~4 as the Initial commit?

Here is my graph history $ git log --oneline --graph

* 0fb5310 four
*   f407eac three
|\
| * 026cb0d Initial commit
* c8ede60 two
* 06dd7e9 one

Upvotes: 0

Views: 81

Answers (2)

Colin D Bennett
Colin D Bennett

Reputation: 12084

As @Amber points out, your branch history is not linear

* 0fb5310 four               HEAD
*   f407eac three            HEAD~1
|\
| * 026cb0d Initial commit   HEAD~1^2  second parent of HEAD~1
* c8ede60 two                HEAD~2
* 06dd7e9 one                HEAD~3

You can use git rebase -p to preserve merges, but apparently (according to the man page for git-rebase) you shouldn't use -p and -i together (which is unfortunate, since that is often useful).

Upvotes: 0

Amber
Amber

Reputation: 526583

Rebase tries to treat history linearly, but merges are not a linear history. As such, if you have merges in your history rebase is not going to show things in the same order that you necessarily committed them.

Furthermore, the ~ operator only goes up the "first parent" path, which means that HEAD~3 is as far as you can go because it's not going down the side branch. HEAD~4 doesn't mean "my fourth commit chronologically before HEAD", it means "the fourth commit before HEAD going up the first-parent side of the history" - in this case, only the * in the first column of the graph log.

Upvotes: 1

Related Questions