This project is a lightweight implementation of Git in Rust. It provides a CLI to perform core Git operations such as initializing a repository, hashing objects, creating trees, and making commits.
The CLI supports the following commands:
Initializes a new git repository in the current directory. It creates the .git directory structure including objects, refs, and HEAD.
cargo run -- initPrints the content of a blob object.
cargo run -- cat-file -p <object_hash>-p: Pretty-print the object content.
Computes the object ID (hash) of a file.
cargo run -- hash-object [-w] <file_path>-w: Optionally writes the object to the.git/objectsdirectory.
Lists the contents of a tree object.
cargo run -- ls_tree [--name-only] <tree_hash>--name-only: List only the filenames.<tree_hash>: The hash of the tree object to inspect.
Creates a tree object from the current directory state. It recursively creates tree objects for subdirectories and blobs for files, writing them to the object store.
cargo run -- write-treeCreates a commit object given a tree hash and a parent commit hash.
cargo run -- commit-tree -m "<message>" -p <parent_hash> <tree_hash>-m: The commit message.-p: The hash of the parent commit (optional).<tree_hash>: The hash of the tree object for this commit.
A high-level command to create a commit. It performs the following steps:
- Reads the current
HEADreference. - Creates a tree object from the current directory (similar to
write-tree). - Creates a commit object linking to the new tree and the current
HEADas the parent. - Updates the
HEADreference to point to the new commit.
cargo run -- commit -m "<message>"-m: The commit message.
Ensure you have Rust and Cargo installed. You can run the project using:
cargo run -- <command> [args]