Search code examples
gitgit-rebaseabort

Git rebase --abort, restore


This happened because git rebase was used without understanding

I ran git rebase, and made some changes, then I ran the "git rebase --abort" command and the changes were deleted, How can I restore these changes, I committed them


Solution

  • So... suppose that you were running a rebase like this:

    git rebase discard-this rebase-this --onto some-branch
    

    And you, at some point, ran git rebase --abort and now you would like to resume the rebase there. There is no way to ask rebase to resume from the old rebase operation.... what you can do is ask rebase to manually start from the point where you aborted.... and for the sake of simplicity, I assume you were rebasing a straight branch.

    So... check git reflog and find the last commit that rebase was able to generate before you aborted. Let's say that this commit (the product of rebase as it is showing up in git reflog) is X-rebased. Then, go to the original branch and find the original commit equivalent to X-rebased and let's call it X-orig. Now, in order to continue with the rebase, you should run this:

    git rebase X-orig rebase-this --onto X-rebased
    

    That should work.