Home > Blockchain >  How to restore deleted file in git if the repository or branch i committed in doesn't exist any
How to restore deleted file in git if the repository or branch i committed in doesn't exist any

Time:03-22

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.

When i run ls it shows me all the files i deleted.(by mistake, somehow)

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:

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 <[email protected]>
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 <[email protected]>
:
 ...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.

CodePudding user response:

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.

Please tell me if it solved your issue.

Regards.

  • Related