Recover from git reset --hard?

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

    The information is lost.

    Since you did not commit, your .git never stored this information. So, basically git cannot recover it for you.

    But, If you just did git diff, there is a way you can recover using the terminal output with the following 3 simple steps.

    1. scroll your terminal and look for the o/p of git diff. Save the o/p in a file called diff.patch
    2. Search & Replace all 7 spaces and 8 spaces with tab(\t) character and save the changes.
    3. Go into your git repository. Apply the diff.patch (patch -p1 < diff.patch)

    You are saved! :)

    Note : While you are copying the data from terminal to a file, be careful and clearly see that the data is continuous output and did not contain any redundant data(due to pressing up and down arrows). Otherwise you might mess it up.

提交回复
热议问题