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 ?
Asked
Active
Viewed 69 times
-2
-
possible duplicate of [How can I undo git reset --hard HEAD~1?](http://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1) – Sascha Wolf Mar 10 '15 at 14:37
-
Sorry I didn't see it :/ – user3651845 Mar 10 '15 at 14:46
3 Answers
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