0

I inadvertently deleted the hidden .git folder and I haven't put my work on a Git remote repo. Is there a way to recover it?

I'm on Arch Linux.

Edit

All my files have been also deleted. 3 weeks of work and rm -rdf with the wrong directory name deleted all of them. I was hoping to find something that can help me to recover my files.

Aboubacar Ouattara
  • 511
  • 1
  • 6
  • 18
  • https://unix.stackexchange.com/questions/10883/where-do-files-go-when-the-rm-command-is-issued – Cory Kramer Feb 11 '20 at 18:02
  • How did you delete it? In theory, the data may still be on your disk but it may be hard to recover the data. If you as of yet have no backup strategy, it may be useful to invest in one to avoid data loss in the future. – k0pernikus Feb 11 '20 at 18:09
  • What's your goal? Pushing your changes to your remote? You may clone the repository anwew, and copy that ones .git folder into your current one and see if it lets you commit. (Or copy your changed files to the new clone and commit and push from there.) – k0pernikus Feb 11 '20 at 18:11
  • @k0pernikus I used git rm which deleted very important files and later (I don't know what took me) I deleted the .git folder ! – Aboubacar Ouattara Feb 11 '20 at 18:15
  • 1
    Have a look at this question: https://unix.stackexchange.com/a/101247/12471 – k0pernikus Feb 11 '20 at 18:17
  • Also relevant: https://unix.stackexchange.com/questions/2677/recovering-accidentally-deleted-files – k0pernikus Feb 11 '20 at 18:18
  • Possible duplicate of [Clone only the .git directory of a git repo](https://stackoverflow.com/q/38999901/11725753) – EvgenKo423 Apr 24 '21 at 15:26

1 Answers1

2

The .git folder is your repository. When you delete that folder you local repository is deleted. You can only recover that folder when you use your backup and restore that folder or you clone the repository again but then your changes until the last pushed commit are deleted.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • 3
    Not until the "last commit" but until the last push! That can be a lot more! The last commit goes to the local repository which was deleted. Maybe the working copy, which is still present, keeps all changes but not the commit history. – Klaus Feb 11 '20 at 18:15
  • In this case yes sure the "last commit" that you have pushed and you pull again. But yes you're right. – René Höhle Feb 11 '20 at 18:39
  • The thing is, I also deleted all of my files. 3 weeks of work and rm -rdf with the wrong directory name deleted all works – Aboubacar Ouattara Apr 25 '21 at 16:47