Skip to content

Latest commit

 

History

History
88 lines (58 loc) · 2.02 KB

Git_Internals.md

File metadata and controls

88 lines (58 loc) · 2.02 KB
# 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

2. Tree

A tree object represents a directory. It contains references to blobs (file content) and other trees (subdirectories).

Example

To create a tree object for a directory:

git update-index --add --cacheinfo 100644 <blob_hash> <file_name>
git write-tree

3. Commit

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.

Example

To create a commit object:

git commit -m "Initial commit"

Relationship Among Objects

  • 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.

Viewing and Inspecting Objects

View Blob Content

git cat-file -p <blob_hash>

View Tree Content

git cat-file -p <tree_hash>

View Commit Information

git cat-file -p <commit_hash>

View Object Type

git cat-file -t <object_hash>

View Object Hash for a File

git hash-object <file_path>

Explore Git Object Database

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.