-2

Following a bad manipulation I have made a "git reset --hard origin/master" on my current working directory. Obviously this erased all my changes which were commited but not pushed. Is it possible to recover them ?

3 Answers3

1

Fortunately , yes you can still recover your lost commits. The git stores your commmit history and can be viewed using the reflog command.

Do this

git reflog

Find your last commit and do this

git reset --hard <commit-id>
cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
1

You are able to recover the state of the file at the last "git add " using this:

$ git fsck --cache --no-reflogs --lost-found --unreachable HEAD

Then take a look at the files in '.git/lost-found/other'.

bmpasini
  • 1,503
  • 1
  • 23
  • 43
0

If you still know the hash of your last commit before doing the reset, you can check it out, provided the garbage collector has not run yet.

Chris
  • 390
  • 2
  • 6