简体   繁体   English

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

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

Please help i have been working on this for a while now!!!!请帮助我已经为此工作了一段时间了!!!!

So i was working on a project and I started playing around with githubDesktop (what can i say I'am really curious) and ended up deleting a repository.I didn't realise it at first but when i opened the project folder most of my file were gone i could only see those from months ago which was the last commit.I dont know if it has anything to do with branching but it shows that I'am currently at head.所以我在做一个项目,我开始玩githubDesktop (我能说什么我真的很好奇)并最终删除了一个存储库。一开始我没有意识到,但是当我打开项目文件夹时,我的大部分时间文件不见了,我只能看到几个月前的那些,这是最后一次提交。我不知道它是否与分支有关,但它表明我目前处于领先地位。

When i run ls it shows me all the files i deleted.(by mistake, somehow)当我运行 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

like so, but im trying to find the commit that this was done and i cant, I also cant find any commits which are atleast close to today which would have helped but i can't it only shows me old commits from other project.When i run, git log --diff-filter=D --summary i get this:像这样,但我试图找到已完成的提交,但我找不到,我也找不到任何至少接近今天的提交,这会有所帮助,但我不能它只显示其他项目的旧提交。当我运行,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.

Note: I was first using github desktop when i lost my file I have tried going to github.com and restoring the repositories(even if im not sure thats the problem) but i can't.注意:我第一次使用 github 桌面时丢失了我的文件 我尝试转到 github.com 并恢复存储库(即使我不确定那是问题所在)但我不能。

If you have not yet run a git gc the branch maybe already inside your reflog , so you have to run git reflog and write down the commit hash related to the deleted branch, then issue git branch <deleted-branch-name> <deleted-branch-last-commit-hash> to recover the deleted branch.如果你还没有运行git gc分支可能已经在你的reflog中,所以你必须运行git reflog并记下与删除分支相关的提交 hash,然后发出git branch <deleted-branch-name> <deleted-branch-last-commit-hash>来恢复被删除的分支。

Please tell me if it solved your issue.请告诉我它是否解决了您的问题。

Regards.问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM