Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck in a git rebase ... how to reset

Tags:

git

rebase

I am part way through a git rebase and I am stuck. I can't remember exactly what happened but I was using a UI and deleted a checked-out branch and things just seemed to go blank. I restarted and managed to do a bit of other work creating and committing to other branches etc but then I noticed a status saying I was still in the middle of a rebase

If I try

git rebase --skip
git rebase --continue
git rebase --abort

each fail with

error: could not read '.git/rebase-merge/head-name': No such file or directory

Is there a way I can get back to a stable state? I'm really not bothered about what the rebase related to so am not trying to get back to point where I am still in the middle of the rebase.

Edit:

$ git status
On branch fix/SJW-01225
Your branch is up to date with 'core-v3/fix/SJW-01225'.

You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")

Untracked files:
(use "git add <file>..." to include in what will be committed)

     [long list of untracked files]

nothing added to commit but untracked files present (use "git add" to track)

Edit-1:

$ touch .git/rebase-merge/head-name

$ git rebase --abort
error: could not read '.git/rebase-merge/onto': No such file or directory

$ touch .git/rebase-merge/onto

$ git rebase --abort
error: could not get 'onto': ''

Thx

like image 588
Simon Woods Avatar asked Mar 07 '19 14:03

Simon Woods


People also ask

How do you get out of rebase in git?

You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit.

How do I terminate a rebase in progress?

If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".


2 Answers

To escape from corrupted git rebase you can do the following

  1. Reset to a known state. You can find out from which commit you started your rebase with git reflog.

For example, reflog will give you the following. The rebase starting point is the last rebase (start) or rebase -i (start) if you did an interactive rebase. Here it is HEAD@{1}:

$ git reflog
f10ccfed (HEAD) HEAD@{0}: rebase : fast-forward
383aa038 (origin/master, origin/HEAD) HEAD@{1}: rebase (start): checkout HEAD~10
0600cf7e (origin/Files, master, Files) HEAD@{4}: checkout: moving from master to Files
0600cf7e (origin/Files, master, Files) HEAD@{5}: commit: fixes
f10ccfed (HEAD) HEAD@{6}: commit: refactoring

So what you need is:

    git checkout master # assuming you were on master
    git reset --hard HEAD@{1}
  1. Remove the rebase-merge folder
    rm -rf .git/rebase-merge
like image 126
nowox Avatar answered Oct 21 '22 05:10

nowox


I somehow got my repo into the same state. In my case, there was no .git/rebase-merge directory, but I did find a rebase-apply directory. Other than the in-progress rebase, git status was clean, so the only thing I needed to do to get out of the weird bad rebase state was to run:

rm -rf .git/rebase-apply/
like image 19
Andrew Patton Avatar answered Oct 21 '22 04:10

Andrew Patton