FM88
FM88

Reputation: 11

How to undo the deletion of my .git/ folder?

Earlier today I was having trouble pushing changes to my GitHub. I stagged several commits but kept getting the message "nothing to commit. branch is up to date". Long story short, I used the rm -rf command to delete my .git/ folder and I re-initialized another .git/ folder. I also deleted my repository and created a new one.

I then noticed my entire code in my text-editor (Atom) had changed and saved itself. Majority of my code went back to being as it was a month ago, with a tiny bit of code that I wrote last week. I contacted GitHub support and was about to get my repo restored. Unfortunately, I had not pushed my code to my repo in a month so of course that was not helpful. I had no idea that deleting my .git/ directory would completely alter my entire project without doing a pull request.

Is it possible to undo the deletion of the .git/ folder? I've seen questions and answers regarding the deletion of other files but not the .git/ folder itself. When I use commands such as git checkout ^HEAD 'fileName', I just get an error. When I use git log I just get the commits from the re-initialized .git/ folder, as expected.

Is there anything I could do to revert everything I did this morning?

Upvotes: 1

Views: 81

Answers (1)

Ronan Boiteau
Ronan Boiteau

Reputation: 10138

Sadly there is no easy way to bring back a folder that you deleted with rm...

rm gets rid of your files for good, there is no "Trash" folder like you would find on Windows. That's the case for your .git/ folder just like it is for any other file.

Depending on your filesystem, you could still give a try to this tutorial on Ext2fs undeletion.

Don't forget to backup your code before doing that kind of hazardous operations.

Upvotes: 2

Related Questions