0

Just ran a git reset --h by accident. I had lots of modified files, and a few new files.

Previous to the reset, I hadn't created a commit, so I can't look in the reflog and revert back to a commit.

Tell me there's a way I can get these files back?! :(

Spikeh
  • 3,540
  • 4
  • 24
  • 49
  • 1
    I can tell you that there's a way to get those files back, but unless you've got copies elsewhere or backups or something, I'd probably be lying... – twalberg Mar 06 '14 at 15:03

2 Answers2

1

No, you cannot get those modifications back.

The only exception would be if you had recently stashed and unstashed them, in which case you could read How to recover a dropped stash in Git?.

Community
  • 1
  • 1
user229044
  • 232,980
  • 40
  • 330
  • 338
  • Unfortunately no stash :| That'll teach me for being too cocky :| – Spikeh Mar 06 '14 at 13:45
  • I have, however, kept VS open... so I've been able to "Ignore Changes" on the reload prompt, and re-save a hell of a lot of the files I had open, so it's not ALL bad. Hopefully I haven't missed anything major... – Spikeh Mar 06 '14 at 13:47
1

Did you add the files to be staged before you reset? If so then the following would work:

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

That will show you something like:

Checking object directories: 100% (256/256), done.
unreachable blob 97145fe866b78bf0ff0d59b0b4d6b69f1446faa9

You can then say

git cat-file blob 97145fe866b > file

That will then add it back to the working tree.

Unfortunately if you did not add or commit the files there is no way to get back unstaged changes after a reset --hard.

Peter Foti
  • 5,526
  • 6
  • 34
  • 47