This project is a minimal Git-like version control system implemented in Python. It provides basic functionalities for working with Git objects, such as blobs and trees. This implementation helps understand how Git internally stores and retrieves data. Inspired by codecrafters build-your-own-git
- Create Blob: Stores file contents as Git blob objects.
- Read Blob: Retrieves and prints blob contents from
.git/objects/
. - Read Tree: Parses tree objects to display file structure.
- Custom Object Storage: Mimics Git's object storage structure.
Ensure you have Python 3 installed on your system.
Clone this repository:
$ git clone https://github.com/omarraf/simple-git.git
$ cd <your-repo-folder>
You can create a blob object by running:
from git_clone import create_blob
content = b"Hello, Git!"
blob_hash = create_blob(content)
print("Blob Hash:", blob_hash)
This will store the blob inside .git/objects/
using Git's SHA-1 hashing mechanism.
To read and display a stored blob:
from git_clone import read_blob
read_blob(blob_hash) # Use the hash generated from create_blob()
This will output the content of the stored blob.
If you have a Git tree object stored, you can read it using:
from git_clone import read_tree
read_tree(tree_hash) # Replace with actual tree hash
This will display the structure of files and subdirectories stored in the tree object.
- The
create_blob
function creates a Git blob by:- Adding a Git header (
blob <size>\0
) - Compressing and storing the content in
.git/objects/
using SHA-1.
- Adding a Git header (
- The
read_blob
function retrieves and decompresses the stored blob. - The
read_tree
function reads and parses a Git tree object.
This project relies on Python's built-in libraries:
os
(File and directory management)sys
(Error handling)zlib
(Compression)hashlib
(SHA-1 hashing)time
(Timestamp handling)