-1

I make sth really stiupid I enter this command (In that time I dont know exactly what it does):

git reset --hard origin/master

and as follows later it probably overwrites my local version with this from remote repository, which is totally NOT what i want to do.

Could you plz tell me how can I restore my local version ? I assume it may be impossible, but I do hope it can be done in some way. I work on Ubuntu 12.04 LTS

CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • Had you ever staged those changes with `git add` or ever committed them with `git commit`? – Peter Lundgren Jul 21 '13 at 14:09
  • possible duplicate of [Undoing a git reset --hard HEAD~1](http://stackoverflow.com/questions/5473/undoing-a-git-reset-hard-head1) –  Jul 21 '13 at 14:42

1 Answers1

2

You can recover the state before by referring the "previous state of HEAD" with the following command:

git reset --hard HEAD@{1}

This will work if committed the changes you were making.

If you haven't committed, but only staged, see this question.

If you haven't committed or staged, you'll have lost everything, except if your IDE/text editor has some recovery features, or backups.

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • That would require the changes to actually have been committed in order to work, just having been staged would not be enough. – qqx Jul 21 '13 at 13:07