Recover from git reset --hard?

后端 未结 22 2942
盖世英雄少女心
盖世英雄少女心 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:33

    You cannot get back uncommitted changes in general.

    Previously staged changes (git add) should be recoverable from index objects, so if you did, use git fsck --lost-found to locate the objects related to it. (This writes the objects to the .git/lost-found/ directory; from there you can use git show to see the contents of each file.)

    If not, the answer here would be: look at your backup. Perhaps your editor/IDE stores temp copies under /tmp or C:\TEMP and things like that.[1]

    git reset HEAD@{1}
    

    This will restore to the previous HEAD

    [1] vim e.g. optionally stores persistent undo, eclipse IDE stores local history; such features might save your a**

提交回复
热议问题