VSCode “Discard all changes” in source control lost 10000 files on my Mac

Help please

I have 10.000 files in my source control in VS code. I messed up initializing the whole user folder as a Git repo. And messed up further by selecting “discard all changes” of uncommitted files and lost everything in my user folder on my Mac. Please help recover them. I don’t have a backup anywhere (Time Machine or ICloud or hard drive). Much appreciated! You are a life saver.

Have you checked your “Trash” folder on your Mac? Sometimes when Visual Studio Code discards stuff, it’ll send it there. That’s the only place I would expect to find it. If it’s not there, you might not be able to recover it.

Also, since VScode is by Microsoft, you might have the files saved in OneDrive, Microsoft’s cloud service. You mentioned you didn’t back any of it up but it might have done it automatically. Check it at any rate. It should be linked to your VScode account.
I feel for you. There is nothing more terrifying than file loss. Don’t worry - you will code much better stuff than you ever lost. And nothing was wasted - if you have over 10,000 files in your folder that means you must have become a master of coding, and the skills you learned along the way creating those is not lost on you.
Wishing you all the best in your search!
Nicolas, a fellow coder.

Nothing in the trash bin. Maybe I need to use a data recovery software?

Thanks for your kind words Nicolas. Actually I am new. It’s more like my Mac is wiped out because I created a git repo for my whole Mac and discarded the repo by accident. Didn’t realise discard all changes deleted all files. Was just thinking it would remove the file from working tree, not my Mac. :smiling_face_with_tear:

1 Like

If you need to do file recovery, you should stop using your system (turn it off).

Get a USB drive and a second hard drive. From a different system, add a bootable file recovery app to the USB drive. Boot the system from the USB and run the recovery. Do not recover the files back to the same hard drive they were lost from.

Doing the recovery from the running system and recovering them back to the same drive is very likely to cause data loss. I’m sure most tools will warn you of this.


Thank you. File recovery is probably my only hope.

I have checked out these suggestions Git - deleted some files locally, how do I get them from a remote repository - Stack Overflow

$ git checkout -f HEAD

Seems promising. But the command will properly overwrite my local changes. Too scared to try :face_with_open_eyes_and_hand_over_mouth:

do you even have a remote repository? did ever use the push command? do you have the link to the remote repository? it doesn’t look that promising

1 Like


sorry you have to go through this.

In case you will revover your data and for the future: I wonder why the commitment was this large? Are running an npm development server and do you have a rule for the server in the gitignore file?

10k+ often indicates that people are trying to commit their development servers (what you should avoid), also GitHub will not accept files of that size so easily either.

If you want to play it save in the future, create a new project on GitHub first and then clone it into your environment. Also develop in different branches and only merge them to the main branch when you are sure about the changes. All of this will prevent data loss disasters.

Best of luck, you got this!


I don’t know how everything is going for you but I have done a bit of research and have a few more suggestions for you.

  1. Try a data recovery software. They can scan your disk for deleted files and might be able to recover them. Among the best are Disk Drill, Data Rescue and EaseUS Data Recovery Wizard.
  2. I don’t know how good you are with bash but you could try checking your git history. Open Terminal and go to your user folder. Put this command in:
git log --stat

That should get you the commit history as well as all the changes you made to each file. Look for commits where you believe the files were still present and note down the commit hash.
Now that you have the commit you think contains the files you’re missing, try checking out that commit to restore the files. Run this command:

git checkout <the hash of the commit you’re looking for>

Put the hash of the commit you’re looking for instead of my text in <>’s up there. This should restore the files to the state they were in at that specific commit.

Of course the chances of this working are low but anything is worth a try. Do things soon because the more time passes, the lower the chances are of you being able to find your lost files as new data replaces old on the disk. Also, you could try talking to ChatGPT about your problem. If you persist and keep giving it updates as you follow its instructions, you can get pretty far. I use it sometimes for my issues and it’s comparatively effective.
@ilenia ‘s suggestion is still probably the best, so try that first. I am not an expert and hardly know any bash so forgive me if I made some errors in my suggestions. At the end of the day, lost data is lost data and there’s no way to get it back without a time machine. (Even then it’s questionable!)
Wishing you luck in your attempts!

1 Like

Thank you.

This went back to when I initialized my home directory as a local git repo, I realised it was a stupid idea. So I used git rebase and git init again thinking the local repo was a different directory now. but git was still tracking untracked files ( in home directory - pretty much my whole laptop) by showing on VScode source control. Then VSCode kept complaining that there were too many active changes. And a lot of the times, I was unable to view any relevant changes unless I completely restarted VSCode. That’s what prompted me to “discard all changes” without understanding what it does. I know now :smiling_face_with_tear:

My mac is M2 chip, I would need a lot of luck to get all my data back. Will try my best.

Yep lesson learned. Cloning a remote repo is probably best practice. I am new to this and learnt this the hard way :sweat_smile: And back up my mac as well.

I have a remote repo but I never intended to upload my whole laptop to GitHub. It was a mistake initializing home directory a local git repo. I wanted to fix it but ended up wiping out my laptop. Those files are untracked and uncommitted. I agree it’s unlikely git can help recover as git does care untracked files in git repo. I am trying to recover my data with data recovery tool.

I tried git log and git reflog. But nothing. Most files in my local repo are untracked. Those i pushed to GitHub are still there on my laptop as well. Git was still tracking untracked files (as in aware they are there) but doesn’t care about those untracked files (pretty much my whole laptop) and never saved in its internal database so i am not positive git can recover my data.m

Yea try not use my laptop now. The more I mess around the less chance I will be able to recover my data.

Actually yes will try chat Gpt. Let’s see what it says. Thank you!

1 Like