What to do if you accidentally deleted your Android project, and without any backups?
So you just created an Android project called FooProject in the Dev
directory. You init git, wrote some code, git add and committed your code but haven’t yet pushed your code to a remote repository like GitHub.
By some bad luck, you typed rm -rf FooProject
in your terminal and deleted the whole directory, nothing is left, not even the .git
directory which is your lifeline to recover your project.
Oh No!
Because rm -rf
is as final as you get. There are no commands to revert the rm -rf
. And attempting to do data recovery with some seedy 3rd party tools you found online is at best unreliable, at worst it’s a SCAM and you installed yourself a keylogger.
Do you panic and flail around, or do you open your mouth to curse the day of your birth?
Don’t worry, not all hope is lost
Android Studio’s Local History to the rescue
Steps to recover:
- In the terminal, create the directory with the same name as the project that you just deleted, in the directory where the project was resided.
mkdir FooProject
- Open up Android Studio > Open > Select the directory you just created, in this case
FooProject
- Right click on the empty project in the Project View > Local History > Show History…
- You’ll see the history of the project, select the most recent history before you made the fatal mistake of deleting the history of your project, Right Click on it, then Revert.
Congratulations! You have just saved your project!
By the way, this method work if you worked on your projects with any of the JetBrains IDE (such as IntelliJ, PyCharm, WebStorm, PHPStorm etc). So you can recover your Python scripts, Spring Boot, Laravel if you accidentally deleted them.
And of course, please do backup your projects.
Thanks for reading.