2

I have rolled back already using this command git reset --hard HEAD^ to some previous commit, all I want to do is rollforward I know this isn't the correct term to what would be my commit that I did latest. Whats happening is a bunch of files were deleted when I used that command and now I don't know how to get back. I am using github is there a way to just pull down from github and overwrite the current directory?

Javier Brooklyn
  • 624
  • 3
  • 9
  • 25
Cool Guy Yo
  • 5,910
  • 14
  • 59
  • 89
  • Just an FYI: if all you really wanted to do is explore your history, you could've checked out the version that you're interested in with `git checkout HEAD^`. That would put your working tree in a detached HEAD state, but allow you to examine history without changing what your branch is pointing to. – John Szakmeister Feb 05 '13 at 09:12

2 Answers2

3

Looking at your question, the commit you want to retrieve is the current one on the master branch of the GitHub repo, you have to do the following

git reset --hard origin/master

WARNING this will erase all uncommitted modifications that you could have made since you rolled back on HEAD^.

Before, you might want to do

git fetch origin

To make sure you've got the latest changes from the GitHub repo.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
1

Take a look at git reflog. Among its output you should find the commit you want to reset to. Then git reset --hard to it and you're back where you were before your first reset.

git reflog is especially useful if you really screw your local repository up and don't have a remote repository you can use to pull commits from. It should work fine as long as you haven't called git prune to get rid of old commits or git reflog expire to clean the reflog.

Jan
  • 11,636
  • 38
  • 47