In this post, we'll see how to create a blob, tree, and commit object in the repository. We'll also learn about the three stages of creating a commit.
Step 1 : First, we'll make a small change to the file and check git status:
Step 2 : Let's add the text-file.txt file and run git status again:
Step 3 : We can edit the file again and run git status:
Step 4 : Let's also add the second change:
Step 5 : Now, all the changes we have made to the file are ready to be committed, and we can record a commit:
Step 6 : The add command creates the blob, tree, and commit objects; however, they are also created when we run the commit command. We can view these objects using the cat-file command
Step 7 : The root-tree object from the commit is as follows:
Step 8 : We can use the git fsck command to check for dangling objects—that is, objects that are not referred to by other objects or references
Step 9 : Let's check the content of the blob using the following command:
The blob was, as expected, similar to the content of text-file.txt when we added it to the staging area the first time.
The following diagram describes the tree stages and the commands used to move between the stages: