Accidentally deleted local folders when trying to remove from git repository. Unable to retrieve.

Accidentally deleted local folders when trying to remove from git repository. Unable to retrieve.



Okay so I'm in a bit of a pickle. I just got started with git, so I'm very much a noob at the moment.



I created a repository in a local folder and through terminal I was able to add and commit files to it. As I was transferring these to my github, I received an error that said some files were too big and some were just unable to go so it failed. Smart me thought that I'd delete one of the folders that may be causing the issue, so I used git rm -r -- <folder> to remove it. That worked, but it also removed it locally as well, so I panicked because I've just lost an entire folder of stuff.


git rm -r -- <folder>



Doing git status showed that the files of that folder were marked 'deleted' but their deletion hadn't been committed yet which meant my next task was to resurrect them. I tried a few things that I found on other similar posts, but the short of it is that I can't find them anymore, they are no longer listed in git_status (although I never committed them) and I have no idea if I'll ever see them again.


git status


git_status



I've tried git checkout, git revert, and I've tried checking deleted files with git log --diff-filter=D --summary and git ls-files --deleted, but it's as if these files never existed.


git checkout


git revert


git log --diff-filter=D --summary


git ls-files --deleted



My first commit included all my files, but I can't seem to get back to that either.



Any ideas on how I can get my files back?





Why did you rm if you did not intend to rm ?
– gogaz
Aug 23 at 13:46


rm





@gogaz because git rm --cached actually would reflect what the OP intended to do (remove from staging area). This works for any other type of committed file, but I don't think it works for deletion. So I really understand the confusion here.
– rubenvb
Aug 24 at 9:36



git rm --cached





@rubenvb that's right, cached was what I intended to do, but I only realised my mistake after making it
– B1ueMang0
Aug 24 at 23:55




1 Answer
1



You have not committed yet. You can get back the last commit with


git checkout HEAD



Be sure to avoid using the following flags without first understanding what they do: -f or --force. These flags permit Git to destroy data. So don’t use them unless you’re sure you want to do that, and know what data you will be deleting.


-f


--force





Is there any way I can get back to my very first commit?
– B1ueMang0
Aug 24 at 23:54





HEAD is a special name which refers to the commit which is currently checked out. You can look at a list of commits with git log, and you’ll see each commit named with some hexadecimal like "commit 12ab34de....". You can run git checkout 12ab34de to check out commit 12ab34de, and then you can git checkout master to go back to the tip of the branch.
– Dietrich Epp
Aug 25 at 1:07


git log


git checkout 12ab34de


git checkout master






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ