Skip to content

Instantly share code, notes, and snippets.

@spikeekips
Last active November 24, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spikeekips/8dba651a1978cfd1f93b to your computer and use it in GitHub Desktop.
Save spikeekips/8dba651a1978cfd1f93b to your computer and use it in GitHub Desktop.
Recover after `git reset --hard`

http://stackoverflow.com/a/6780036/229734


I accidentally ran git reset --hard on my repo today too while having uncommitted changes too today. To get it back, I ran git fsck --lost-found, which wrote all unreferenced blobs to <path to repo>/.git/lost-found/. Since the files were uncommitted, I found them in the other directory within the <path to repo>/.git/lost-found/. From there, I can see the uncommitted files, copy out the blobs, and rename them.

Note: This only works if you added the files you want to save to the index (using git add .). If the files weren't in the index, they are lost.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment