我刚刚在github上创建了一个新的存储库.从一个装满文件的文件夹开始,我所做的步骤是:
git init
git add -A
git remote add origin ...
#Now pull in the first commit that github made
git pull origin master
#Check everything is OK
ls
Run Code Online (Sandbox Code Playgroud)
伊克!我的所有文件都消失了!发生了什么?我能把它们还给他们吗?
jth*_*ill 12
你可以把它们拿回来.即使唯一指向它的是索引,git add仍然将添加的内容放在回购中.我首先git fsck要找到一个"晃来晃去"(git略有古怪的"未引用"拼写)blob和git cat-file -p那些blob,如果有太多我会做的话find .git/objects -type f | xargs ls -lt.
小智 6
对我来说以下工作有效:
我希望它有帮助!
小智 5
我同意已接受的答案,但就我而言, 的结果太多了git fsck。这个解决方案帮助我找到了丢失的文件:
在丢失的文件中搜索字符串:
grep -rin <string_in_missing_file> .git/
Run Code Online (Sandbox Code Playgroud)
例如:
grep -rin MyClassName .git/
Run Code Online (Sandbox Code Playgroud)
搜索结果:
.git//lost-found/other/3cfaa36226f52a5c1b38c2d2da3912656c998826:5:class MyClassName extends ParentClass
.git//lost-found/other/e7b8923de4afb230ad523b5b515f50cb9c624248:5:class MyClassName extends ParentClass
Run Code Online (Sandbox Code Playgroud)
其中搜索结果是:
.git/<path_to_file>:<line_number_of_found_string>:<found_string_and_context>
Run Code Online (Sandbox Code Playgroud)
然后恢复文件:
git cat-file -p 3cfaa36226f52a5c1b38c2d2da3912656c998826 > ../<desired_file_path>/MyClassName.php
Run Code Online (Sandbox Code Playgroud)