Day 10: Understanding Git Object Absolute Names
In the Git version control process, each version represents a commit object. Since branches are often created during version control, the resulting commit graph can be quite complex. Therefore, how to identify different versions or quickly locate specific versions to obtain information becomes very important. This article will help you understand commonly used object name concepts and usage methods in Git.
Object Absolute Names
In Git, each object has an id computed by SHA1 hashing, and this id is the so-called “absolute name.” If the object is a commit object, then this is the absolute name of the commit object. So as long as we find the absolute name of the commit object, we can get that version at any time. As indicated by the arrow in the following figure, this is the commit object id we obtained through git log. We can obtain detailed information about that commit object at any time.

If we want to see the content of the commit object in the above figure, we can use git cat-file -p commitid to get it, as shown in the following figure:

Short Syntax for Object Absolute Names
Since the Git object id is the result of SHA1 hashing of the content, it is quite long (40 characters). When specifying the “absolute name” in Git, you can use just the first few characters instead, with a minimum of 4 characters. This means that “absolute names” between 4 to 40 characters in length can all be used to identify an object.
For example, we can also see from the above figure that the content of this commit object contains a tree object, which also has an absolute name of 07c1321be49815d53eb2413f0ad5286010ebb6cc. So I can also use git cat-file -p treeid again to get the content of that tree object, as shown in the following figure:

Sometimes we want to get version records and will use the git log command, which will also output comparison results of changes for each file. The results will be very long. At this time, you can use the git log --pretty=oneline command to get more concise historical records, and you can also get the complete “absolute name” of the commit object, as shown in the following figure:

Another commonly used technique is to output only part of the “absolute name.” You can execute it through the git log --pretty=oneline --abbrev-commit command, as shown in the following figure:

Today’s Summary
The above is the usage of absolute names. Due to the characteristics of Git objects, you can access any object in the Git repository through the absolute name of the object. There are many more git commands that will use absolute names. Familiar with these concepts and expressions, you will better master Git objects.
Let me reorganize the Git commands and parameters learned today:
- git log
- git cat-file -p [object_id]
- git log –pretty=oneline
- git log –pretty=oneline –abbrev-commit
- Back to Table of Contents
- Previous Day: Comparing File and Version Differences
- Next Day: Understanding Git Object References and Symbolic References