0

I messed up with git after running git reset --hard HEAD~3 and lost 2 hours worth of work. I then found a post on here that explained git reflog.

When I want to return to "git reset HEAD@{1}", how do I not only return, but have all files that were removed put back in their directories?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
LondonGuy
  • 10,778
  • 11
  • 79
  • 151
  • On Stack Overflow it is not necessary, or recommended to use salutations, valedictions or signatures in questions and answers. In other words, you shouldn't say "I would like help", or "Thanks", because that is why you are here, and we are. – the Tin Man Jan 21 '12 at 18:41

1 Answers1

3

You will need to move the branch that you want to be at that point with

git branch -f master HEAD

The above example moves the branch master to HEAD. So it requires HEAD to be at the point you want to move the branch to. If that isn't the case you can use the commit hash or reflog entry instead of HEAD.

If you never commited the files before the --hard reset, the work is gone. Git will only be able to recover what you commited.

Andy
  • 44,610
  • 13
  • 70
  • 69
  • I only use one branch and that's master. So your response is all I would need to type? – LondonGuy Jan 20 '12 at 15:07
  • So git branch -f master HEAD@{1} ? Should do the trick? or git branch -f master 6a4034b ? – LondonGuy Jan 20 '12 at 15:11
  • Yes, but that point changes every time head moves, so if you already did `reset HEAD@{1}`, that value will have moved already. – Andy Jan 20 '12 at 15:14
  • Yea, I re-checked using reflog. Anyway running above gives me this error: Cannot force update the current branch – LondonGuy Jan 20 '12 at 15:15
  • 1
    That means you have that branch checked out and are trying to move it out from under yourself. Since that is the case, you could always do `git reset --hard HEAD@{1} and accomplish the same thing. – Andy Jan 20 '12 at 15:19