我执行了"git rm -rf ."命令(尝试清除我在执行"git add ."之后移除的文件缓存),但没有考虑到git会物理删除这些文件。我还没有进行过初始提交/分支。
$ git init
$ git add .
我记得要添加我的“.gitignore”文件。然后,因为懒惰又不想查找正确的命令,我执行了以下操作:
$ git rm -rf .
现在,Git所追踪的每个文件都不见了。糟糕。
如何使用悬挂的blob恢复文件?
$ git fsck
notice: HEAD points to an unborn branch (master)
notice: No default references
dangling blob 45cb2316b079df7898a28bab1389c87d37de4da5
dangling blob 06b9d0f91bb0643a54ec027efc0efd6645d95326
dangling blob c6c828230bc129da40928d55297577421c6f2e79
dangling blob 087b296f5ae80151fb0d6150927ebe8049ed7706
dangling blob c957743cb7ea533ce772d178394ce9f656b17b7c
dangling blob 0ea745612b105394f5cd5c0119a829de98a0a954
dangling blob 8fb1fa03c12cd56d4e2284008e92a3666bc60b93
dangling blob cf49a6cf77ac792b108577c01ccf88cb2c28228c
dangling blob 93817d9eeefea6ea894544e78b0e0970aa5adc46
dangling blob 94a9ed024d3859793618152ea559a168bbcbb5e2
dangling blob 574b7130959f2278c88946cf385fc49adcdf28c2
dangling blob 582f5bceb8b35c01fd7442678a3cd7e1088b7957
dangling blob d9fb7ca5775745b4332f630400d52c979aab35cd
dangling blob 2087b182bf8b4b8d5ed8fe45a50c7661bda25feb
dangling blob 6109baf32d04410c84d860501057a7f55a13f9dd
dangling blob 22cc2ac7585b1d47bccf2ecb7bf57e16c2142bb6
dangling blob 63b329443cc27273fad14c1e41de5bb9bf1bdd03
dangling blob a2296d429715c9b6d730fdcc972eefdf8273d2e2
dangling blob e41aedd7b2dbdee8b965a30d40ed0c9275194984
dangling blob 6dc7b06e8f03cda72cf223b050d07ccd2b850fc8
dangling blob ee52d86d94a40e7092dc34d1b2760244ec7dccaf
dangling blob 2ffa08c086d3702563d498c9069a345940b3a348
dangling blob 6fafa07526ad288ff2f6e26810ed9818eb18aabb
dangling blob b1cdf17b5bb40b4839cfc80f7e91bbcf7b94f798
dangling blob 353db77b88c248c752cdbd914787b9ebdf2d700f
dangling blob f61d3492ce0d0e396fd322114a5e3475886de1cc
dangling blob 7756a8713095390f5b106b81ae7f7247f762970b
dangling blob bc995b7f9f6806dd5678227579a515bb5768d3a0
dangling blob fce4a77b63b25abbc010859b4037589983820329
dangling blob 3e3335f8cd27168d4fe81f61421d647f2905b7b0
dangling blob 7f56efed4f8706e5b79408afbde197964d824eab
我四处搜索只能找到有关恢复悬空提交的教程。
(trying to purge the cache of files I had removed after doing "git add .)
实际上可以使用git reset
或git rm --cached
(注意最后部分)来完成。请注意,这是针对清除已删除文件的缓存而言。 - underscore_d