1

The thing comes like this:

I got a local branch which is far ahead of remote branch.

And when I merge them, there is a tone of conflicts to be fix.

So I came to stackoverflow to ask how to set the remote branch data the same as my local branch.

Someone gave me this command: git rebase origin/master --strategy=ours

I did this under my local branch, and now my local branch is revert back to the same old commit of the orgin/master! I used git log, and the last commit was the same as the remote branch, all those new commits are disappeared, that's five days' work.

Is there any possible way to recover my local branch data?

Zen
  • 4,381
  • 5
  • 29
  • 56

3 Answers3

3

If you are on your local branch, try a git reset --hard ORIG_HEAD.

If that doesn't work, have a look at git reflog: you should see your previous local branch SHA1 there.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I personally think here the name `YOUR_ORIGIN_HEAD` could reduce misunderstood. Because in this world there are always many newbees, like me. – Zen Jan 10 '15 at 10:29
2

use git reflog to find the SHA1 of your last commit before rebase and check it out.

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • Ah, I got this, I think the command I used just removed commit reference from my branch, the commit itself didn't vanished in git, am I right? – Zen Jan 10 '15 at 10:26
  • yes, the commits stay at your local repository for quite some time until garbage collected. – Mykola Gurov Jan 10 '15 at 11:27
1

The two answers above are quite good. And through their help I found my way to solve this.

First, I used git reflog, then I saw a list which contains the recent commits of my local branch.

I chose the newest commit, and did git reset --hard HEAD_OF_THAT_COMMIT, then I recovered my branch!

Zen
  • 4,381
  • 5
  • 29
  • 56