user95025
user95025

Reputation: 175

Did git rebase on origin by mistake

How do I revert my rebase? I was on local branch(abc) and wanted it to rebase it with origin. Following are the commands that I issued:

git checkout live
(On branch live)
git pull

After this, I THINK I forgot to switch back to my local branch 'abc' and I started rebasing it and when I ran 'git status' command, I realized that I rebased live branch locally.

git status
On branch live
Your branch is ahead of 'remotes/origin/live' by 13 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

I don't want to push anything but and want to delete those 13 commits that it is showing. What is the correct way of doing this?

Upvotes: 0

Views: 128

Answers (3)

o11c
o11c

Reputation: 16056

In general, read git reflog to figure out where you want to reset to.

In this case you seem to know you want to reset to origin/live (but do check git log origin/live..live to be sure).

Once you know what you're resetting to, run git reset --hard commit-to-reset-to, in this case git reset --hard origin/live.

Upvotes: 2

Amilcar Andrade
Amilcar Andrade

Reputation: 1171

You can use git reset --hard <SHA> to go back to your original state. I will recommend to create an experiment branch first.

Also read and check the following documentation - http://git-scm.com/docs/git-reset

Upvotes: 3

cdhowie
cdhowie

Reputation: 168998

Use the git reflog command to show you the reflog for your current branch. This is data maintained locally that has a history of each commit that your local branches pointed to. You can use this data to find the commit that your local branch pointed to before the rebase.

If rebasing is the last operation you performed then git reset --hard HEAD@{1} should undo this operation (and it will also discard any changes you have made to the working tree).

Upvotes: 1

Related Questions