Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

How to Recover Deleted Code Using GitLab (or Git)

Tiempo de lectura: 3 minutos

Reading time: 3 minutes

Many times in our project, we may accidentally delete a piece of code or simply want to revert to a previous version that was already working. If we use GIT in our project, this task becomes quite simple, with just one detail – we need to upload the commits to be able to recover them.

Let me provide an example of how to recover previously deleted code.

To begin, I’ll create a small project in GitLab that contains a text file called test.txt

Next, I’ll synchronize the project with GITHUB DESKTOP. If you also want to use this Git client, you can visit the previous article on Using GitHub Desktop as a Client for GitLab and Other Git Services

In the document, I’ve added the text that appears on the screen: “Texto anterior a borrar. Este es un documento de prueba” (Text prior to deletion. This is a test document).

Now, I’ll commit and push the changes.

Once the commit has been added to GitLab, I’ll delete the phrase “Texto anterior a borrar” (Text prior to deletion). Then, I’ll push another commit with this change.

Now, let’s suppose we want to recover the first commit that contained the complete text.

To do so, we need to go to the GitLab website and select our project.

Once the project is selected, click on commit to search for the commit you want to consult.

Continuing, select the primera versión (first version).

Now, click on “examinar archivos” (browse files) to navigate through the files and find the one you want to restore or consult.

Now, when opening test.txt, I can see the document reconstructed with the entire initial text.

This is how easily you can recover the content of your commits using GitLab. I hope you no longer fear making mistakes with this trick.
0

Leave a Comment