Rebase doesn't normally preserve merges, you have to pass the -p
or --preserve-merges
flag to get it to do that.
However, your process for synchronizing with the remote is incorrect, and might lead you to rewriting commits that have already been pushed and shared with other people, which can lead to a lot of problems with synchronization and conflicts.
If you wanted to do a squash, then instead of doing a pull and a merge, you should have fetched and rebased instead:
git fetch origin
git rebase origin/mainline mainline
git rebase -i mainline~2
You can combine the last two commands if you want, but doing them separately has the advantage that you can then verify that you didn't mess anything up with the squash by doing git diff mainline@{1}
afterwards.
So, to get out of your current situation, you could do a hard reset back to mainline^
, or whichever commit you were at before you tried to do the merge/pull, then run the rebase commands above.