Recover from git reset --hard?

后端 未结 22 2887
盖世英雄少女心
盖世英雄少女心 2020-11-22 00:52

Is there any way to recover uncommitted changes to the working directory from a git reset --hard HEAD?

22条回答
  •  庸人自扰
    2020-11-22 01:45

    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 /.git/lost-found/. Since the files were uncommitted, I found them in the other directory within the /.git/lost-found/. From there, I can see the uncommitted files using git show , 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.

提交回复
热议问题