Git rebase undos all changes/commits to local branch

46 Views Asked by At

I made some local changes and then committed them (let's call this commit A). I then made and committed some more small changes (commit B), and since I didn't want to clutter up my commit history with a bunch of small changes, I tried to squash commit B into commit A. Basically I wanted the remote's commit A to represent what I had in my local immediately after making commit B.

I tried git rebase -i HEAD~3, and squashed commit B into commit A.

This then reverted the local branch to what it was before BOTH A and B. I managed to revert this using git rebase --abort, but I am confused as to why this happened, especially as I have used git rebase -i HEAD~N in the past to achieve the desired results.

1

There are 1 best solutions below

4
jwielink On

Would be easier to git reset HEAD~2 —soft and commit again.

As to why your commits were lost, I’m not sure, normally this should work if you use the interactive rebase to squash commit B into A:

s b1cf5f0ffc <COMMIT B>
pick e24a3f5975 <COMMIT A>
pick 8785438d31 ...