0

I accidentally deleted all of my files whilst trying to push them to GitHub in what would have been the first commit (I have no idea how I managed this).

I have no local backup and no remote backup but in my GitLens VSCode extension the files are still there and viewable: enter image description here

How can I revert my current file tree back to what's being shown in GitLens?

Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49
  • 1
    what do you see when you try `git log` ? I don't know GitLens that much, but if it is still able to see your code, it means that your code must be stored in some local commit – mr.mams Apr 07 '20 at 10:04
  • @mr.mams I've just checked the repository on GitHub and the files are all there in a previous commit. Any idea how I can revert to that commit? – Daniel_Knights Apr 07 '20 at 10:07
  • 1
    You can check here : https://stackoverflow.com/questions/215718/how-can-i-reset-or-revert-a-file-to-a-specific-revision?rq=1 – mr.mams Apr 07 '20 at 10:17
  • @mr.mams If I use git checkout I get this message: ```error: The following untracked working tree files would be overwritten by checkout: public/css/app.css public/js/app.js public/mix-manifest.json Please move or remove them before you switch branches. Aborting``` – Daniel_Knights Apr 07 '20 at 10:22
  • 1
    Seems like you have local changes that are not committed yet. You can use `git stash` to keep these changes aside. Then you can try again to use `git checkout` – mr.mams Apr 07 '20 at 10:33
  • @mr.mams I now have that commit back but for some reason my node_modules folder and vendor folder are in a separate commit. Could I merge the two together some how? – Daniel_Knights Apr 07 '20 at 10:45
  • 1
    node_moduls and vendor folder should not be uploaded to git . For using them package.json and composer.json are engough – Ariful Islam Apr 07 '20 at 11:02

2 Answers2

2

Since you can see in gitlens, it means your files are present in previous commit.

You can do checkout to get it back as @mr.mams mentioned. You can also undo your commit, check How do I undo the most recent local commits in Git?

To merge two commits you need to squash your commits. Check Squash my last X commits together using Git

Srinivasan
  • 33
  • 4
0

I managed to recover all the files aside from vendor and node_modules, ran npm install and composer install and this fixed that issue. Still not sure how this happened though. Will have to brush up on my git skills methinks.

Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49