Spikeh
Spikeh

Reputation: 3695

Git: Reverting a git reset --hard

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?! :(

Upvotes: 0

Views: 140

Answers (2)

Peter Foti
Peter Foti

Reputation: 5654

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.

Upvotes: 1

user229044
user229044

Reputation: 239240

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?.

Upvotes: 1

Related Questions