Timmy O'Mahony
Timmy O'Mahony

Reputation: 53971

Abort an (accidental and old/dangling) rebase but keep all changes

I am working locally on a branch (master). I previously made a rebase to squash some commits which I thought worked. I continued to make a number of commits until I needed to perform another rebase. When I called git rebase -i HEAD~3 I got the error:

Interactive rebase already started

suggesting that I never properly finished the old rebase.

Now I want to abort the old rebase, without losing any of my changes since it began. I was going to use

git rebase --abort

but I'm pretty sure that will remove all my local commits and put be back before the rebase. What can I do here?

Upvotes: 4

Views: 1024

Answers (1)

Christopher
Christopher

Reputation: 44234

Commit them. Abort the rebase. Pull the commit from git reflog.

git add .
git commit -m "Rebased changes"
git rebase --abort
git cherry-pick HEAD@{1}

Do with it what you will. If your git reflog expired (I can't imagine a situation where this would occur in normal day-to-day operations), cut a new branch then abort the rebase:

git add .
git commit -m "Rebase changes"
git checkout -b rebased-master
git rebase --abort

Upvotes: 5

Related Questions