2

I made a mess on my branch after trying to rebase to the master.

In my commit history, I had quite a bit of refactoring (renaming and moving), along with deletion of classes. And I SHOULDN'T have pushed to the remote repository. (I know, I'm kicking myself ever since).

However, what's done is done. Now since the rebase rewrites the history and commits(?) (by the conflict resolving during the rebase), I can not reset to an earlier commit HEAD~2 to start over, all the commits were rewritten and with wrong commits.

I can get a snapshot of the HEAD~2 from git, is there way for me merge (rebase) the snapshot back to my branch, rollback the changes, and start over?

Thanks in advance!

David

Update, from our internal git web page, I can see the previous commit:

commit  6f577850231fed07eebdacd3bc5862f84356d803
tree    8be1d60056697bc1b8d7284c4e85a6d1738ac3e2    tree | snapshot
parent  1ca61d4dd69b7be649906834d44bb7fec390153d    commit | diff

And I'm able to download a snapshot in gz by clicking the "snapshot" link. However, when I try to do:

git checkout -b newBranch 6f577850231fed07eebdacd3bc5862f84356d803

I got:

fatal: reference is not a tree: 6f577850231fed07eebdacd3bc5862f84356d803

If I run:

git checkout -b --force newBranch 6f577850231fed07eebdacd3bc5862f84356d803

I got:

fatal: git checkout: updating paths is incompatible with switching branches.

I guess this commit only resides on the remote repository? How can I checkout it out in git then?

Solution: This SO answer is the solution to my problem: Undoing a git rebase

Community
  • 1
  • 1
David Zhao
  • 4,284
  • 11
  • 46
  • 60
  • 1
    `I made a mess on my branch...` and your SO question... really? just one long line of text? i'm definitely not going to read that, you really need to learn how to be organized. – KurzedMetal Jun 14 '12 at 18:30

1 Answers1

2
fatal: reference is not a tree: 6f577850231fed07eebdacd3bc5862f84356d803

The OP David Zhao found that an incomplete rebase or an invalide HEAD reference could also trigger that message:
"Undoing a git rebase"

Ie, git reset --hard HEAD@{x}, with 'x' being a HEAD reference found in git reflog.


Initial answer: it happens also for submodules (which wasn't the case here)

See "Git submodule head 'reference is not a tree' error":

someone made a super-project commit that refers to an unpublished commit in the submodule sub.

So, if you have submodules, you need to make sure the parent repo and the submodules are in sync, and fetch the parent repo (updating their history as displayed in your gitweb page) to your local repo, before you can start checkout any commit.
And if that commit is from a submodule, go to that submodule directory first before doing that checkout.

From there, you can merge that branch back to the one you have pushed (let say, for instance, 'master'), creating a new commit (so no history rewriting), picking one of the methods described in "git command for making one branch like another".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • We don't have submodules. I think the commit is detached from the branch, so it doesn't belong to parent. Though I can still download the whole source tree in a tarball. Can this be the case? Is there a way for me re-attach it? Thanks! – David Zhao Jun 14 '12 at 21:47
  • @DavidZhao do you see (after a fetch) that commit in your reflog? (`git reflog`) http://blog.pioneeringsoftware.co.uk/2012/01/13/reference-is-not-a-tree is about reattaching a branch... but again within a submodule. So are you *sure* no submodules are involved? – VonC Jun 14 '12 at 21:47
  • I'm sure that we don't have sub modules. Actually, I was pointed to this SO question: http://stackoverflow.com/questions/134882/undoing-a-git-rebase git reflog and git reset --hard HEAD@{5} worked like a charm – David Zhao Jun 19 '12 at 02:53
  • @DavidZhao ok I have edited my answer to reference that solution, for more visibility. – VonC Jun 19 '12 at 07:48