3

I've made a big mistake of rebasing a branch into master instead of the master into branch. So now instead of having changes of master in a branch, I have master that's out of sync with remote repo.

How can I take changes back?

Uko
  • 13,134
  • 6
  • 58
  • 106

2 Answers2

3

If your remote repo is still ok, just

git checkout anybranch
git branch -D master
git fetch --all
git checkout master
Sergi
  • 2,872
  • 2
  • 25
  • 24
  • Take a look to the solution provided by @AdamDymitruk. Even if you've solved your problem with my answer, to know git reflog is a must on most occasions. – Sergi May 30 '12 at 14:25
3

When you make mistakes with the branches and where they point, you can get rescued by git reflog.

git reflog

will show you where the branch was pointing to before. So if your rebase is wrong, you can "undo" it by pointing the branch to where it used to be with:

git reset --hard HEAD@{1}

Change 1 to be another number depending where the commit that you want is in the list that reflog provides.

The reflog is also useful for many other mistakes one can make.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141