1

I was playing around with git, I'm not really good with it, I know a little bit about it and while i was trying to make the .gitignore work on a different branch so I issued

$ git rm -r --cached .
fatal: pathspec '.' did not match any files

So I was looking for some options for git rm , I accidentally pressed enter and typed git rm, and now almost all the files that I've been working on for months are now gone, how will I recover it back?

TheBAST
  • 2,680
  • 10
  • 40
  • 68

2 Answers2

0

Simple, reset the HEAD.

git reset HEAD

I just found similar question. Refer this question for more explanation.

R4444
  • 2,016
  • 2
  • 19
  • 30
  • 1
    I am stuck on a different branch and not in the master ? Should I continue it ? – TheBAST Nov 07 '19 at 05:44
  • Yes, refer this question for more explanation - https://stackoverflow.com/questions/2125710/how-to-revert-a-git-rm-r – R4444 Nov 07 '19 at 05:47
0

On your current branch, where you have done the rm, the more modern way to restore your files would be using git restore (Git 2.23+):

git restore --source=HEAD --staged --worktree -- .
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250