Skip to content

ikram98ai/git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Git Implementation

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.

Features & Usage

The CLI supports the following commands:

init

Initializes a new git repository in the current directory. It creates the .git directory structure including objects, refs, and HEAD.

cargo run -- init

cat-file

Prints the content of a blob object.

cargo run -- cat-file -p <object_hash>
  • -p: Pretty-print the object content.

hash-object

Computes the object ID (hash) of a file.

cargo run -- hash-object [-w] <file_path>
  • -w: Optionally writes the object to the .git/objects directory.

ls-tree

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.

write-tree

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-tree

commit-tree

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

commit

A high-level command to create a commit. It performs the following steps:

  1. Reads the current HEAD reference.
  2. Creates a tree object from the current directory (similar to write-tree).
  3. Creates a commit object linking to the new tree and the current HEAD as the parent.
  4. Updates the HEAD reference to point to the new commit.
cargo run -- commit -m "<message>"
  • -m: The commit message.

Building and Running

Ensure you have Rust and Cargo installed. You can run the project using:

cargo run -- <command> [args]

About

implementing parts of git from CodeCrafters

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages