The behavior of git rebase -i
is different when you have merges in the subset of commits under rebase and if you don't have. In your case, you first merged, and then you want to rebase on a subset of commits which contains merges.
Generally, I avoid rebasing merge commits to keep things simple.
As @thescientist said, in you case, it's better to squash commits at merge time than after the merge.
One remark that might be helpful:
Normally when you invoke git rebase -i
on a linear history, you see your list of commits, and you don't change anything (just keep pick
), no operation will happen, and no history will be rewritten
However, when you find yourself accidentally running git rebase -i
on a too big subset of commits, which involves merge commits, you will often see a big list of commits, and if you don't change anything (keep pick
), git will start rewriting those commits, which is most often not something you wanted.
To escape from this situation, delete all the lines; normally when some lines are deleted during rebase, git removes the commits corresponding to those lines, but if you remove all lines, git will do nothing - which is a helpful way to abort when you messed up something - because if you wanted to drop all commits, you'd use git reset --hard <desired_commit>
.