# Understanding Git Objects
Git uses three main types of objects to store and manage data: blobs, trees, and commits. These objects form the backbone of Git's version control system.
## 1. Blob
A blob (Binary Large Object) is a simple object that stores the content of a file. It represents the contents of a file at a specific point in time.
### Example
To create a blob object for a file:
```bash
echo "Hello, Git!" | git hash-object -w --stdin
A tree object represents a directory. It contains references to blobs (file content) and other trees (subdirectories).
To create a tree object for a directory:
git update-index --add --cacheinfo 100644 <blob_hash> <file_name>
git write-tree
A commit object contains metadata about a particular set of changes. It points to a tree object that represents the state of the project at that commit. Commits also have parent pointers, forming a history of changes.
To create a commit object:
git commit -m "Initial commit"
-
Blob to Tree: Blobs store the content of files. Trees reference blobs for file content.
-
Tree to Tree: Trees reference other trees for subdirectories.
-
Tree to Commit: Commits reference a tree object representing the project state at that commit.
-
Commit to Commit: Commits form a chain with parent pointers, creating a history of changes.
git cat-file -p <blob_hash>
git cat-file -p <tree_hash>
git cat-file -p <commit_hash>
git cat-file -t <object_hash>
git hash-object <file_path>
ls .git/objects
Understanding Git objects is crucial for grasping the inner workings of Git. Use the provided commands to explore and inspect these objects in your Git repository.