to recover files that were added to the index but whose changes were lost (e.g. git reset --hard)
git fsck --unreachable | grep commit | cut -d\ -f3 | xargs git show
git fsck --unreachableto get all the items that are unreachablegrep committo filter out all entries except for commits (the index will show up as a commit)cut -d\ -f3to filter out all but the SHA1sxargs git showto show all of the contents of the objects.
Once you've identified the SHA1 that contains the changes that were lost, check it out to get the working tree back into the state of the index at the time git reset --hard was run.
git checkout -p <SHA1>
to apply the changes that were lost as a patch instead of replacing the tree wholesale, git apply can be used.
git apply <(git diff <SHA1>^ <SHA1>)
Accidentally
git added way too much and it was easier to look through fsck than think which changes should be reset. Though in my case I had to look at unreachable blobs (and not commits) instead. Thanks!