How to recover all your code when accidentally using Git Reset Hard with Intellij Idea

Visa
3 min readAug 3, 2019

--

This article aims to guide for a newbie who just learns to develop software with IntelliJ Idea Ultimate Version and Git.

Intellij Idea

A few days ago, I faced an issue where I used reset hard in git in order to revert to the previous commit in the local git repository because I thought my teammate commit all his work to the repository successfully. Unfortunately, he did not commit all the files to the repository, as a result, we lost tons of code and furious how to get back all the code. Intellij Idea saved the day.

I checked the google for a while and I found one thread mention about Local History under VCS tab in Intellij tool where you can get all the code back. At that point, I think this could help me to get some code and eventually, this feature is so cool.

IntelliJ IDEA Toolbar

The Local History is in the VSC toolbar of Intellij Idea where you can revert the file from the history of a local machine and this feature saved the history for a few days.

In this feature, the user can revert the file to the previous version or revert a whole project to where it used to be.

In order to revert, the user has to stand on the file that user what to revert then tab on VSC -> Local History -> Show History.

Sidebar selected on Specific File

From there the user can choose to revert the file version from any version of change by right click on the file version then click on revert.

VSC —> Local History —> Revert

Note: At the dialogue, there is a button to Create Patch, I will explain that in another post.

On the other hand, the user can revert a whole to the previous version as well. By standing on the top file of the hierarchy of the project at the left sidebar, then the user tab on VSC -> Local History -> Show History and do same as restoring the previous version of the file.

Sidebar — Selected on Project

User can also revert multiple times to match the version that you need it without any problem.

Thank Intellij that creating this awesome feature that I will never forget and it saved my final project from disaster because my teammate wrote thousands line of codes and did not commit a single file due to committing in the wrong directory. At the end of the today, Intellij IDE saved the day.

--

--

Visa

A computer science student strives to work in the top 500 tech companies in the US. buymeacoffee.com/visatch