Table of Contents

Once you have learned the basics of Git it’s a good idea to familiarize yourself with the various Git objects, and how they relate to each other.
Keys and Values
Every object in Git is assigned a key, specifically a SHA-1 hash, and the value is the object itself. You have surely noticed each commit is identified by a long string of characters, for example, this output from a simple git log
:
However, it is not only commits that receive a SHA-1 hash, but all of the other objects get a hash as well. This is how Git can quickly identify different types of content, and allows you view objects by their hash, if needed.
What Are The Git Objects?
Here are the main Git object types:
- Commits
- Tags
- Files (known as “blobs”)
- Directories (known as “trees”)
Git uses the unique SHA-1 hash assigned to each of these objects for quick and reliable identification. For example, each tag references a commit; which means the hash associated with that tag always references the hash of the commit it references, even if the tag name changes.
Working With Git Objects
For most every day usage, there are some instances in which you might reference an object by its hash.
For example, if you want to checkout a commit you will use the checkout
command you will use the first 5 or so digits of the commit hash.
For referencing branches and tags, you can simply use the name of the branch or tag. However, using the hash will work as well.
But how do you find the hash for a tag? The Git cat-file
command can give you information about different objects. For example, if you wanted to get information about a tag:
For example, if you have a tag named v1.0
, you can run this command:
And receive an ouput similiar to this:
This output tells you what “tree” (snapshot) the tag references, what the parent commit hash is, as well as the author and committer name, as well as the commit message.
If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.
CentOS, Debian, or Ubuntu
No Bloatware
SSH and Root Access