0

I just made a HUGE mistake. (I obviously don't know enough about git)

I was trying to update my directory on remote. I created a dev branch then typed git fetch && git checkout dev. Why? Because BitBucket said so! (I know. I'm a f****** idiot). Well, now all of my files have either been removed or changed to what I had days ago. I just lost A LOT of work.

Please tell me how I can get my work back. PLEASE!

EDIT: I'm not trying to revert to a previous commit. I'm trying to revert my local files back to what I had moments ago before my git fetch && git checkout dev mistake.

Jay
  • 57
  • 1
  • 1
  • 6
  • Check `git log` and restore a previous commit. [This has been asked many times here](http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit) and I don't think it's worth repeating again. Just look at that solution. – taco Feb 13 '15 at 22:03
  • Try `git checkout -` to go back to previous branch (you didn't use **`-f`** option when switching branches, did you?) – Jakub Narębski Feb 13 '15 at 22:05
  • thanks a lot. I tried searching and did reset --hard. It didn't work. I'll look some more – Jay Feb 13 '15 at 22:05
  • No i didn't. I'll try. – Jay Feb 13 '15 at 22:06

1 Answers1

0

Woohoo, I figured it out! Here's what I did:

git reflog
2fe6344 HEAD@{0}: checkout: moving from master to dev
f1cc9bc HEAD@{1}: commit (initial): camera doesnt work
git reset f1cc9bc
git checkout .

That's it! I honestly couldn't find this anywhere on SO and I'm usually pretty darn good at researching. If this answer already exists, I'm sorry. But hopefully it helps someone out there in a tough jam.

Jay
  • 57
  • 1
  • 1
  • 6
  • `git checkout -` (that's a minus here; the command is patterned after `cd -`) does use reflog to switch to previous branch; there is also `@{-}` generalization. In your case `git checkout -` is roughly equivalent to `git reset f1cc9bc && git checkout .` with respect to files, but it also switch branch back. – Jakub Narębski Feb 14 '15 at 11:49