1

is there anyway to revert and recover a git rebase operation after --aborting it?

I did a git rebase --abort after the following rebase output:

On branch feature/cool-feature-x
Last commands done (20 commands done):
   pick bd4c3q commitA
   pick e53wr1 commitB
  (see more in file .git/rebase-merge/done)
Next commands to do (7 remaining commands):
   pick ws5b4 update
  (use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'feature/cool-feature-x' on 'as34y5'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

git log: gives me an older commit as expected. Say the last commit i.e last-working-commit git reflog has all the history as expected. I want to use HEAD{2}

git reset --hard HEAD{2} to the last change I did gives me this:

warning: Log for ref HEAD unexpectedly ended on Sun, 5 Jun 2018 16:15:19 
+0300 (last time I made the changes before `git rebase --abort`)

However last-working-commit is still the same. and every time I run the same command, i get multiple last-working-commit in log

reference Questions: Undoing a git rebase

Git: how to undo merge during rebase

EDIT:

git reset seemed to have worked even after the warning. it was creating the same last commit every time but after switching back to the branch i originally did rebase on, HEAD was actually reset as I wanted. I don't know why it behaved this way, and there was that warning.

Fatah
  • 2,184
  • 4
  • 18
  • 39

1 Answers1

1

This warning, as you seen, does not prevent the reset to work.

It (the warning message "warning: Log for ref HEAD unexpectedly ended on...") comes from refs.c#write_pseudoref()

It is tested here:

test_expect_success 'Query "master@{2005-05-28}" (past end of history)' '
    test_when_finished "rm -f o e" &&
    git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
    test $D = $(cat o) &&
    test "warning: Log for ref $m unexpectedly ended on $ld." = "$(cat e)"

That means, at one point Git is checking the log of HEAD while it is resetting, and consider said log being "past the end of the (reset) history" of the previous branch it references.
Once the reset is complete, I expect the git log is coherent again (with the new "end of history")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250