1

I accidently pulled an update from rails app on heroku which has messed up my local code.

Is there any way to undo this stuff.

I was trying to commit some changes I made locally to bitbucked, then I got the error that I need to pull and then only I can commit. When I pulled, I see that my local code is messed up.

Any way to undo the git pull heroku?

Michael Victor
  • 861
  • 2
  • 18
  • 42
Suraj
  • 2,423
  • 12
  • 39
  • 75

3 Answers3

2

In that case, you need to reset your HEAD to where it was before. You can do git log to get to the commit in which you were working before, and after that, write the following command:

get reset `sha1 of that commit`
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
1

if

git pull heroku

is the last command, meaning you didn't change branch or did commits or anything.

git reset HEAD~1

will do the trick, else you will need to run

get reset sha1 of that commit just before git pull merges

(hopefully you dont have to go this far) while doing git pull, if it rebased instead of merge, then you will have to find the sha1 sum using

git reflog

krazedkrish
  • 638
  • 3
  • 10
0

The good news: you cannot destroy anything by pulling. You have simply added a few commits on top of your last and made your branch point to a different commit, easily undone.

git log                      # find the commit you want to go back to, let's call it a1b2b123b123
git branch BRANCH a1b2b123b123 --force    # substitute your real branch name for BRANCH
git checkout BRANCH

Save the output of git log so you have something to hold on to in case you get lost.

The stuff added by the pull will be garbage collected after a while.

AnoE
  • 8,048
  • 1
  • 21
  • 36