How to recover files from missing tree and dangling blobs?

后端 未结 2 1914
抹茶落季
抹茶落季 2021-01-27 23:22

After git add . I ran git rm -r -f .,and all my local files were deleted accidentally. After recovering them with git fsck --lost-found I

相关标签:
2条回答
  • 2021-01-28 00:13

    I tried to reproduce what you did:

    1) git add .

    2) rm -r -f *

    after this I think that you made a git reset, or git reset --hard (wrong choice: it overwrote the index with an empty one because you never did a commit)...

    but the correct command were as indicated in my previous answer git checkout-index -af (but this is useless after the reset)

    at this point you gave correctly the git fsck --lost-found, my suggestion was equivalent with lower level commands (git cat-file...)

    so: why gibberish?

    Are you sure that in the directory there was only source code files and not (for example) compiled versions of the python files (extension .pyc)? Perhaps in some hidden directory created by a IDE?

    0 讨论(0)
  • 2021-01-28 00:20

    1) rm -r -f . should abort without effect probably you did rm -r -f * and it does not delete the .git directory

    2) this is confirmed by the fact that the command git fsck --lost-found did not abort

    in this situation (deletion of just the working directory) the correct command to recover as much as possible is:

    git checkout-index -af : this copies the version currently on the index (the one that you just put with git add .) to the working directory

    0 讨论(0)
提交回复
热议问题