1

I did a git add from my VScode, then I saw there were some files I didn´t want to push so I did a git rm -rf to take away everything. I am a newbie (didn't expect this).

Is there a way to restore my files after this?

I m on a Mac and already tried git reset, git checkout. Any help would be great!

rioV8
  • 24,506
  • 3
  • 32
  • 49
PGCL
  • 11
  • 3
  • 1
    is it a new branch/repo with no history? – eftshift0 Sep 29 '22 at 18:39
  • restore from trash? – IamK Sep 29 '22 at 18:41
  • 3
    don't execute command you don't understand – rioV8 Sep 29 '22 at 20:34
  • `git rm -rf` should generate an error similar to `fatal: No pathspec was given. Which files should I remove?`. Did you do something like `git rm -rf *`? You might try `git reset --hard`, but make sure you understand what that does before you execute it. – William Pursell Sep 29 '22 at 21:07
  • 1
    If you have staged the file, git can help you retrieve the content but not the file names. There are 3 good answers (and one from me ) on that here: https://stackoverflow.com/questions/11094968/in-git-how-can-i-recover-a-staged-file-that-was-reverted-prior-to-committing/58853981 – Philippe Sep 29 '22 at 23:06
  • Were the files committed and the commits pushed somewhere? – knittl Sep 30 '22 at 07:26
  • Hi in the end i got it fixed. My friend found this page and the command git stash and I was able to recover my lost files. To answer all your questions I didn't a prior branch and repo @eftshift0. – PGCL Sep 30 '22 at 10:06
  • couldn't restore it from trash @C1sco :) all good now – PGCL Sep 30 '22 at 10:07
  • nope they weren't @knittl – PGCL Sep 30 '22 at 10:07
  • everyone has their own learning curve @rioV8, mines a bit bumpier than yours. hope you have a good day! – PGCL Sep 30 '22 at 10:09
  • @WilliamPursell I tried the `git reset --hard` but it didn't work for me the `git stash` command did the trick for me! – PGCL Sep 30 '22 at 10:10
  • if I have a bumpy ride and park my car against a concrete wall I have to live with the consequence, nobody will fix it for me. – rioV8 Sep 30 '22 at 14:42
  • the `f` in `-rf` means `force`, that means there is no way back, or they will add an option `-ff` meaning `are you really sure` – rioV8 Sep 30 '22 at 14:44
  • @rioV8, I think getting aid and feedback from outside is always a good option, to each their own, though. – PGCL Sep 30 '22 at 16:51

0 Answers0