如果我提交的存储库或分支不再存在,如何恢复 git 中已删除的文件

How to restore deleted file in git if the repository or branch i committed in doesn't exist anymore

请帮忙,我已经为此工作了一段时间了!!!!

所以我在做一个项目,我开始玩 githubDesktop(我能说什么我真的很好奇)并最终删除了一个repository.I 一开始没有意识到,但是当我打开项目文件夹时,我的大部分文件都不见了,我只能看到几个月前的文件,这是最后一个 commit.I 不知道它是否有任何关系有分支,但它表明我目前处于领先地位。

当我 运行 ls 时,它会显示我删除的所有文件。(不知何故错误地)

PS C:\Users\curti\Desktop\MFLS> ls                                             


    Directory: C:\Users\curti\Desktop\MFLS


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        20/03/2022     10:23                .idea
d-----        04/03/2022     15:03                django-csp
d-----        20/03/2022     09:55                media
d-----        20/03/2022     09:56                MFLS
d-----        20/03/2022     09:56                MFLS_main
d-----        20/03/2022     09:56                registration
-a----        12/03/2022     17:53         180224 db.sqlite3
-a----        11/01/2022     14:01            682 manage.py
-a----        15/01/2022     07:56            164 Pipfile
-a----        15/01/2022     07:56           4819 Pipfile.lock

像这样,但我试图找到已完成的提交,但我找不到,我也找不到任何至少接近今天的提交,这会有所帮助,但我不能它只显示旧的提交从其他 project.When 我 运行, git log --diff-filter=D --summary 我得到这个:

PS C:\Users\curti\Desktop\MFLS> git log --diff-filter=D --summary
warning: refname 'HEAD' is ambiguous.
warning: refname 'HEAD' is ambiguous.
commit 828d61868e0601152849bef2575c0b4142d51a0e
Author: Curtis Arissol <curtisarissol286@gmail.com>
Date:   Wed Aug 4 11:44:03 2021 +0400

    having problem with task or to-do bar but partially completed and working

 delete mode 100644 classy/index.js
 delete mode 100644 classy/views/index.js

commit 8cf9c230ad49a3712151ff109b978bb3288257cd (checking-old-auth)
Author: Curtis Arissol <curtisarissol286@gmail.com>
:
 ...and other old commits.

注意:我第一次使用 github 桌面时我丢失了我的文件 我尝试去 github.com 并恢复存储库(即使我不确定那是问题所在)但我可以't.

如果您还没有 运行 git gc 分支可能已经在您的 reflog 中,所以您必须 运行 git reflog 并写下与已删除分支相关的提交哈希,然后发出 git branch <deleted-branch-name> <deleted-branch-last-commit-hash> 以恢复已删除的分支。

请告诉我它是否解决了您的问题。

此致。