Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Did i just destroy my work by incorrectly using git rebase [duplicate]

I executed the following line:

git rebase -i dev --onto master  

I figured this would cut my dev branch and paste it on top of my master branch. And the -i would let me collapse the changesets.

But when it brought up the editor, I did not see any of the changesets. All I saw was "noop". So I just exited it. And then I look at my git history, all my changes are gone. My dev branch is at the same place my master is at!

Can some one help me recover? Thanks!

like image 743
Aishwar Avatar asked Oct 19 '12 22:10

Aishwar


People also ask

What happens if I rebase twice?

Yes, you can rebase more than once. After rebasing, you get a fresh set of commits. These commits are exactly like all other commits and hold no record of having been rebased.

Is git rebase destructive?

First of all, you must understand that Git rebase is a destructive operation. Git generates new commits based on your previous commits onto the target branch. Your former commits will, therefore, be destroyed. Basically, you rewrite your Git history!

How do I undo a rebase abortion?

You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit.


1 Answers

Git makes it hard to lose work.

Run:

git reflog 

Than look for the commit that was just before the rebase

Then check it out

git checkout <sha> 

Look around, is it the version you wanted to recover?

If so, create a branch here

git checkout -b mybranch 
like image 149
Christoph Avatar answered Oct 21 '22 11:10

Christoph