gitrebase

"Cannot 'squash' without a previous commit" error while rebase


I have the following in the to-do text of git rebase -i HEAD~2:

pick 56bcce7 Closes #2774
pick e43ceba Lint.py: Replace deprecated link

# Rebase 684f917..e43ceba onto 684f917 (2 command(s))
#
...

Now, when I try to squash the first one(56bcce7) and pick the second one by adding "s" before the first, I get the following error:

Cannot 'squash' without a previous commit

Can someone explain me what it means, and how do I do it?

I want to squash the first commit(56bcce7) and "select and reword" the second(e43ceba) commit


Solution

  • Interactive rebase presents commits in the reverse order of what you are used to when using git log. git rebase -i replays the selected commits in the exact (top-down) order they are listed in the saved rebase instructions file. When squashing, the commit selected for squashing is combined with the commit that precedes it in the (edited) list, i.e. the commit from the previous line. In your case - there is no previous commit for 56bcce7. You have to do one of the following