1

My situation: There are two remotes, origin and fork (the latter is owned by me). I checked out origin/devel, changed some code and committed like 5x to my local branch test. I pushed my commits to fork/test.

Then I started an interactive rebase, while on my local test branch:

git rebase -i --onto origin/devel

Git opened an editor with a list of my 5 commits, ready to pick, squash or whatever.

I accidentally closed the editor instead of deleting everything or Ctrl+C and git rebase --abort in git console. Thus, it started the rebase.

In order to undo it, I used git reflog and git reset --hard HEAD@{...} and also git checkout fork/test -B test later, since my remote should also contain the pre-rebase state. All of them seem to recover the state, but if I start the rebase again, there will be no commit in list (only a noop entry).

How do I recover the original state before the rebasing, so that the original commit list is shown again?

Undoing a git rebase does not cover this issue. I'm mainly interested in why this happens and how to really revert the rebase, not how to alter the rebase command to get the commit list again (as I said, git reset and git checkout did NOT undo it properly from my point of view).

The ultimate goal is to rebase my test branch onto the up-to-date origin/devel at some later point, squashing all my own commits since test diverged from origin/devel.

//edit: It looks as though Git forgot the fork-point. git merge-base --fork-point origin/devel does return the origin/devel commit before my own commits however, and git rebase -i that-commit gives me the initial commit list. So why does --onto not do the same anymore?

Community
  • 1
  • 1
CodeManX
  • 9,290
  • 3
  • 41
  • 58
  • Why does the linked question not cover the issue? Move your branch's HEAD back to where it was before and then you can start over from square one. – siride Sep 09 '15 at 03:30
  • It was at my latest (5th) commit before rebasing, and so is it after a reset to the latest commit of `fork/test` (I did not push after the rebase). Yet, rebasing it again with the identical command does not give the same commit list. Instead, I get a blank list, unless I explicitly specify the common ancestor commit. Why doesn't it find that ancestor implicitly anymore? – CodeManX Sep 09 '15 at 03:38
  • Try `git rerere forget` ? – FractalSpace Sep 09 '15 at 03:38
  • @FractalSpace: How is that related? I did not have any merge conflicts. – CodeManX Sep 09 '15 at 03:40
  • Most tools resolve simple conflicts automatically. If you have any of such installed, such as kdiff3, meld, vimdiff, chances are they may be playing a role. Its just a guess, worth trying. – FractalSpace Sep 09 '15 at 03:48
  • I'm using Notepad++ on Windows (as editor, not merge tool obviously) and there was no merging and no conflicts when I ran the first rebase. If there are conflicts, TortoiseGitMerge or some similar msysgit merge tool is used. `git rerere forget` just gives an error that it's deprecated to call without path, and that it couldn't write the rerere record. – CodeManX Sep 09 '15 at 03:51
  • I noticed one difference between the states before and after the rebase: `git status` reported "Your branch is ahead of origin/devel by 5 commits", whereas it now reads "Your branch is up-to-date with fork/test". I shouldn't really matter however, because I explicitly specify `origin/devel` as new base. It kinda makes sense if no commit is listed if I'm ahead of `origin/devel` and not behind by a single commit, but why did it list my commits the first time then? `git rebase -i origin/devel` works, it doesn't with `--onto`, but it did initially. – CodeManX Sep 09 '15 at 04:06
  • I don't think you're resetting properly. The old commit is still in your repo. If you reset your branch back to that commit, you *will* be in the same spot you were in before the rebase. Git doesn't delete or rewrite history, so unless you've done a garbage collection or pruning, you should be able to do a complete restore. – siride Sep 09 '15 at 13:36
  • Isn't the purpose of rebasing to alter history? :) By old commit, do you mean the rebase commit? I'm not sure if my last commit before the rebase appears before the rebase commit in reflog... Or should I explicitly reset to the hash of refs/remotes/fork/test (remote HEAD, which should be < rebase commit)? – CodeManX Sep 09 '15 at 14:03
  • @CoDEmanX: heh, good point. I'm referring to the commit that represents the HEAD of the branch you're on *before* you did the rebase; that is, the commit that you would have seen if you did `git rev-parse HEAD` before you started your disastrous rebase. If you can reset HEAD to that commit, it'll be as if you never rebased at all. – siride Sep 09 '15 at 20:43
  • Well that would be the latest commit of my remote branch `fork/test`, because I pushed before the rebase. But it doesn't work. Or the same commit I got locally, to which I reverted to using reflog and reset/checkout HEAD@{#}. It didn't work. What's weird is that all hashes up to my last commit in reflog are identical... Shouldn't there be a change after rebase? Or is it irreversible? See here: http://pastebin.com/NkwXgD4v – CodeManX Sep 10 '15 at 00:52

0 Answers0