How to get back to the earlier version on Git - 7

Git Logo
 In this tutorial, we are going to learn how to get back any version of the project. We have a text file (Employee.txt) where we added the Salary of the employee in the previous tutorial. So in first commit, it was only the Employee's name. And in the second commit, we added the salary of each employee. 
As a result, now our project has two versions. One is without salary and another is with salary.
 




Current status is each employee has their salary in that text file. Now we will get the earlier version of Employee.txt file. Where salary not available.

Current File Data - with salary
Current Data Image



Step 1: Go to git bash and see the all commit log by the below command. We can use two commands. The first command (git log) is shows with author details and date time. And second command (git log --oneline) only shows the commit ID and comment in a single line.
git log
Git Log Image

or
git log --oneline
Log oneline

fe0bed1 (HEAD -> master) My commit - Salary Added
21b75c7 My comment - First Commit

See here (fe0bed121b75c7) are the git unique commit id. Using this unique id we are able to get back the each version of commit.

Step 2: Now we will get the first version of Employee.txt file using this (21b75c7) commit id.
Command -  
git checkout 21b75c7
Checkout command
Moved to earlier version

Here it has been moved to the earlier version of the Employee.txt file. Below is the current data inside Employee.txt file. Which are earlier versions (without salary). 

Earlier version data pic
Earlier version backed

Done... 👍

Next tutorial we will learn about the branch of git. That is most important.

Post a Comment

0 Comments