2

I messed up on my rails app so I used the command:

$ git checkout -f

to go back to my previous commit and get rid of my screw ups. After research I see that this command undos all local changes! Now my app is showing the initial commit of the project in Firefox and I cannot seem to get it back to the latest commit and show all of the work that I have done so I can test it in my browser. I have tried three of the tactics in this post How do I undo a checkout in git?

$ git reset --keep

$ git checkout master

$ git reset --hard HEAD

but I still am seeing the application as it was when I first started the project. When I type in...

git status

terminal shows that I am on branch master. I am still seeing all the commits when running git reflog. How can I get my application back so that I actually see all the local changes and can keep testing the app in my browser?

Community
  • 1
  • 1
Tim
  • 99
  • 1
  • 11

1 Answers1

1

It's good that you know what the reflog is and how to view it. Pick the latest commit that you want to keep from the reflog, and:

git reset --hard abc123

where abc123 is the SHA1 of the commit you want. That will update master (your current branch) to the commit abc123, along with all the history implied by that..

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Its weird... I just tried this '$ git reset --hard c13a3d3' and the result I get in terminal is what I would expect 'HEAD is now at c13a3d3 Added users...' which is the latest commit. But when I go to my application in the browser I still see a very old version of my project. Is this a git bug? I am using git version 1.7.4.4 on Mac OSX 10.7.2. Thanks so much for the help! – Tim Feb 10 '12 at 03:05
  • I would first check that the files in your Git working directory appear as you expect them to be. The problem you're seeing is unlikely to be a Git bug; it's more likely to be some step that you've forgotten to do that you normally do to compile/build/deploy/whatever your code. – Greg Hewgill Feb 10 '12 at 03:31