Rollback a pushed rebase

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).

  • Cannot syncdb “DatabaseError: no such table: django_site”
  • Connecting Eclipse project to new GitHub repo
  • git archive with LibGit2Sharp
  • Need to understand Git/Gerrit command (fetch & push)
  • Failed to push some refs to remote repository (prohibited by Gerrit)
  • Forking vs. Branching in GitHub
  • 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

  • How do I include a .gitignore file as part of my npm module?
  • Using GCC Through Git Bash
  • Push to GitHub fork takes no effect, says all commits up to date, but made some changes
  • Don't work git in Android Studio
  • How to change topic name of Gerrit via command line
  • Migrating virtualenv and Github between computers
  • One Solution collect form web for “Rollback a pushed rebase”

    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”.

    Git Baby is a git and github fan, let's start git clone.