Let's Understand How Git Maintains History Of Version Or Commit Ids 📥📤 With Details

Introduction

 
In my previous article, I described more details on Git's complete flow, how to push changes from local git to GitHub and what is git add, git commit, git status, git push commands. Also, I describe how the developers share code from a single repository.
 
In this article, I will describe the below-mentioned points in detail.
  1. How Git maintains a history of version or commits ids 
  2. How Git maintains version controlling system
  3. How Git maintains commit ids during push changes from local Git to GitHub
Note
Before going through this session, please visit my below-mentioned session related to Git and GitHub.

Git maintains Version IDs or Commit IDs

 
Now, we go to the Local Dev One workspace and try to pull the latest changes and see what happens as shown below
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
It shows the message that it's already up to date. That means there are no new changes available in the GitHub repository. If you go to the local git repository that .git directory then you find a file called HEAD as shown below. 
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
There you can see one ref path that is refs/heads/main. So, We need to go this path and find out the file called main as shown below.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
Here in main File you can see commit id is 993a754918f12e841eeab79cbd125720e96347f3. That is nothing but the Version ID. As per an earlier discussion, Git is a version controlling system and it maintains a version for each modification we perform. 
 
So, If we go to GitHub repository and check this version id is 993a754918f12e841eeab79cbd125720e96347f3 as shown below.
 
First, click on 3 commits.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
Here you the version id in the short format as shown below. So, To see the details of version id click on Changes made by Local Dev One.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
So, after clicking on Changes made by Local Dev One, you can see the version id in detail in the code section as well as in-browser URL. 
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details
 
The same commit id is shown in both the local git repository and GitHub repository as earlier discussed. Now, we see what this + and - symbol inside the content of files in the GitHub repo.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details
 
Here Local Dev One wants to modify a file called MyFile.cs as shown below.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details
 
Here we check the status to see the modified file as shown below. The details of untracked files and Changes not staged for a commit are described in the previous article.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details
 
Let's commit this MyFile.cs to the stage area as shown below. The below commands are described in the previous article.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
Now let's go to the local .git repository and check the commit id in the main file of this path is refs/heads/main. There you can see the different commits as per the latest changes made in MyFile.cs as shown below.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
So, every time Git maintains the different version id based on each modification and tracks the history. So, Git is called a version controlling system. Now we check the same version id should be there in the GitHub repository. For this, the file should be pushed from local git to the GitHub repository as shown below.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
As of now, I have one branch called main which is the default one instead of the command that is git push origin main, We can give only as git push. But when there are many branches and we need to push changes to a specific branch of the GitHub repository then we should follow this command is git push alias name of git repo branch name. According to this format I have given git push origin main. Here origin is alias name of git repo and main is branch name. As I already have pushed the changes using a command that is git push. So, that here when I run using a command that is git push origin main then it shows Everything up-to-date. That means there are no new changes available in a local git repository.
 
Now if I go to my GitHub repository then I can see the latest changes with comments added during commit changes.
 
The message I have given. 
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
The added content in MyFile.cs.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
You can see a total of 4 commits and click on the latest commit to check the new Version ID or commit ID as the same as local git.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
Now you can see the new commit ID as shown below. Also, there is showing 1 changed file with 2 additions and 0 deletions. There is 2 addition that means two + symbols. One symbol means there one new line space and another plus symbol means for new property country name added. Here we can see both the commit IDs are the same.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
Now Local Dev One wants to remove one line in MyFile.cs as shown below.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details 
 
Then push these changes from local git to GitHub repository using the same steps as described earlier.
 
 Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details
 
Now let's see the changes made in the file MyFile.cs and what this - symbol means. It shows 1 changed file with 0 additions and 1 deletion. Here deletion means the Local Dev one has removed the PostId property line from MyFile.cs file.
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details
 
Here we can see the user name with day and time details who has committed the changes e.g. satyaCsgithub committed 17 minutes ago as shown below. 
 
Let's Understand Git Maintains History Of Version Or Commit Ids 📥📤 With Details

SUMMARY

 
In this write-up, we have learned the below details,
  • How Git maintains history of version or commit ids
  • How Git maintains version controlling system
  • How Git maintains commit ids during push changes from local Git to GitHub
  • What addition and deletion symbol means
****Thank You & Stay Tuned For More****