Complete reference for all git-rs commands with educational insights.
git-rs init
Initialize a new git-rs repository.
git-rs init [directory]
Creates a new git-rs repository in the current directory (or specified directory), setting up the complete .git-rs/
directory structure needed for version control.
.git-rs/
βββ objects/ # Content-addressed object database
β βββ info/ # Object database metadata
β βββ pack/ # Packed objects (future feature)
βββ refs/ # Reference storage
β βββ heads/ # Branch references
β βββ tags/ # Tag references
βββ HEAD # Current branch pointer
βββ config # Repository configuration
βββ description # Repository description
# Initialize in current directory
git-rs init
# Initialize in specific directory (future feature)
git-rs init my-project
.git-rs/
and all subdirectoriesrefs/heads/main
git-rs add
Stage files for the next commit.
git-rs add <file>...
git-rs add <directory>...
git-rs add .
Reads file content, creates blob objects in the object database, and updates the staging area (index) to include these files in the next commit.
File Content β Blob Object β Object Database β Index Update
"Hello" β "blob 5\0Hello" β SHA-1 hash β .git-rs/objects/aa/bb...
# Add single file
git-rs add README.md
# Add multiple files
git-rs add file1.txt file2.txt
# Add directory recursively
git-rs add src/
# Add all files in current directory
git-rs add .
.git-rs/objects/
// Blob object format
let content = b"Hello World";
let header = format!("blob {}\0", content.len());
let object = [header.as_bytes(), content].concat();
let hash = sha1::digest(&object); // 5d41402abc4b2a76b9719d911017c592
// Storage location
// .git-rs/objects/5d/41402abc4b2a76b9719d911017c592 (compressed with zlib)
git-rs status
Show the working tree status.
git-rs status
Compares the working directory, staging area (index), and HEAD commit to show what files have been modified, staged, or are untracked.
Files in the staging area that differ from the last commit:
Changes to be committed:
new file: README.md # New file staged
modified: src/main.rs # Modified file staged
deleted: old_file.txt # Deleted file staged
Files in working directory that differ from staging area:
Changes not staged for commit:
modified: README.md # File modified after staging
deleted: old_file.txt # File deleted after staging
Files in working directory not in staging area:
Untracked files:
new_feature.rs # New file not yet added
temp_file.txt # File not tracked by Git
# Show repository status
git-rs status
# Typical output interpretation:
# - Green (staged): Ready for commit
# - Red (modified): Changed since last add
# - Untracked: Not under version control
1. Scan working directory β compute file hashes
2. Load staging area (.git-rs/git-rs-index) β get staged hashes
3. Load HEAD commit β get committed hashes (if any)
4. Compare hashes:
- staged β committed β "Changes to be committed"
- working β staged β "Changes not staged"
- working exists, not in staged β "Untracked"
Working | Staged | HEAD | Status |
---|---|---|---|
exists | same | same | Clean (no output) |
exists | same | none | New file (staged) |
exists | same | diff | Modified (staged) |
exists | diff | same | Modified (unstaged) |
exists | none | none | Untracked |
exists | none | same | Deleted (staged) |
none | same | same | Deleted (unstaged) |
git-rs commit
Create a new commit from the staged changes.
git-rs commit -m "<message>"
git-rs commit --message "<message>"
-m, --message <MSG>
- Commit message (required)Creates a permanent snapshot of all staged changes, building a complete directory tree and updating the current branch reference to point to the new commit.
# Commit staged changes with a message
git-rs commit -m "Add user authentication system"
# After staging files:
git-rs add src/auth.rs
git-rs add tests/auth_tests.rs
git-rs commit -m "Implement secure password hashing"
// Example commit object structure
let commit_content = format!(
"tree {}\nparent {}\nauthor {} <{}> {}\ncommitter {} <{}> {}\n\n{}",
tree_hash, // Root tree SHA-1
parent_hash, // Previous commit SHA-1
author_name, author_email, timestamp,
committer_name, committer_email, timestamp,
commit_message
);
// Object format: "commit <size>\0<content>"
// Storage: .git-rs/objects/ab/cdef123... (compressed)
# Example tree built from staging area:
100644 blob a1b2c3d4 README.md
040000 tree e5f6g7h8 src/
100644 blob i9j0k1l2 main.rs
100644 blob m3n4o5p6 lib.rs
040000 tree q7r8s9t0 tests/
100644 blob u1v2w3x4 integration_tests.rs
# Before commit
cat .git-rs/HEAD # ref: refs/heads/main
cat .git-rs/refs/heads/main # 1234567890abcdef... (parent commit)
# After commit
cat .git-rs/refs/heads/main # abcdef1234567890... (new commit)
git-rs diff
Show changes between different states in unified diff format.
git-rs diff [--cached]
Displays line-by-line differences between:
--cached
: Show differences between staging area and last commitdiff --git a/file.txt b/file.txt
index 1234567..abcdefg 100644
--- a/file.txt
+++ b/file.txt
@@ -1,3 +1,3 @@
line 1
-old line 2
+new line 2
line 3
# Show unstaged changes
git-rs diff
# Show staged changes
git-rs diff --cached
# After modifying a file
echo "new content" >> file.txt
git-rs diff # Shows the addition
git-rs clone
Clone a repository from a remote location.
git-rs clone <url> [directory]
Creates a complete local copy of a remote repository, including all objects, references, and history. Sets up remote tracking and checks out the default branch.
1. Parse Remote URL β Validate and extract repository information
2. Discover References β GET /info/refs?service=git-upload-pack
3. Request Pack File β POST /git-upload-pack with wanted refs
4. Download Objects β Receive and decompress pack file
5. Create Local Repo β Initialize .git-rs structure
6. Setup Remote Config β Configure origin remote tracking
7. Extract Objects β Unpack objects into local database
8. Update References β Create local branches for remote refs
1. Checkout HEAD β Populate working directory
# Clone to directory with same name as repository
git-rs clone https://github.com/user/repo.git
# Clone to custom directory name
git-rs clone https://github.com/user/repo.git my-project
# Educational example with local path (for testing)
git-rs clone /path/to/existing/repo.git local-copy
GET /info/refs?service=git-upload-pack HTTP/1.1
Host: github.com
Response:
001e# service=git-upload-pack
004a5d41402a refs/heads/main\0 side-band-64k ofs-delta
0000
POST /git-upload-pack HTTP/1.1
Content-Type: application/x-git-upload-pack-request
0032want 5d41402abc4b2a76b9719d911017c592
0000
.git-rs/objects/
format[remote "origin"]
url = https://github.com/user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
# HTTP clone (uses Git wire protocol)
git-rs clone https://github.com/user/repo.git
# Local clone (direct file system copy)
git-rs clone /path/to/repo.git local-copy
cloned-repo/
βββ .git-rs/
β βββ objects/ # All repository objects
β βββ refs/
β β βββ heads/ # Local branches
β β βββ remotes/ # Remote tracking branches
β β βββ origin/ # Origin remote branches
β βββ HEAD # Points to default branch
β βββ config # Repository configuration
β βββ remotes/ # Remote configuration
βββ file1.txt # Working directory files
βββ directory/
βββ file2.txt
Git-RS implements the βsmartβ HTTP protocol used by modern Git servers:
Pack File Structure:
- Header: "PACK" + version + object count
- Objects: Compressed and delta-encoded objects
- Checksum: SHA-1 of entire pack file
# Network errors
Error: Failed to connect to remote repository
Cause: Connection timeout or DNS resolution failure
# Authentication errors
Error: Repository not found or access denied
Cause: Private repository requiring authentication
# Protocol errors
Error: Invalid pack file received
Cause: Corrupted data or protocol mismatch
git-rs log
Display commit history in reverse chronological order.
git-rs log [-n <count>]
β οΈ Currently Not Implemented - This command is planned for future development.
Show the commit history starting from HEAD, walking backwards through parent commits to display the repositoryβs evolution over time.
# Show all commit history
git-rs log
# Show last 5 commits
git-rs log -n 5
# Show last 10 commits
git-rs log --count 10
This command requires:
--git-compat
FlagPurpose: Choose between educational mode and Git compatibility mode for directory structure.
Syntax: Add --git-compat
before any command.
# Educational mode (default) - Safe for learning
git-rs init # Creates .git-rs/ directory
git-rs add file.txt # Uses .git-rs/git-rs-index
# Git compatibility mode - Interoperable with real Git
git-rs --git-compat init # Creates .git/ directory
git-rs --git-compat add file.txt # Uses .git/index
Educational Insights:
When to Use Each Mode:
Mode | Use Case | Directory | Index File |
---|---|---|---|
Educational (default) | Learning Git internals safely | .git-rs/ |
git-rs-index |
Compatible (--git-compat ) |
Testing with real Git tools | .git/ |
index |
Examples:
# Safe learning environment (default)
mkdir learn-git && cd learn-git
git-rs init # Creates .git-rs/
echo "test" > file.txt
git-rs add file.txt # Safe - won't conflict with real Git
# Git compatibility testing
mkdir test-compat && cd test-compat
git-rs --git-compat init # Creates .git/
git-rs --git-compat add file.txt
git status # Can use real Git to verify!
# After adding a file, explore the object:
git-rs add hello.txt
# Find the object (hash will be displayed during add)
find .git-rs/objects -name "*" -type f
# Examine object structure (requires zlib tools)
zpipe -d < .git-rs/objects/5d/41402abc... | hexdump -C
# View staging area (our index is JSON for readability)
cat .git-rs/git-rs-index | jq .
# See what's staged
jq '.entries | keys[]' .git-rs/git-rs-index
# See current branch
cat .git-rs/HEAD
# List all branches (when implemented)
find .git-rs/refs/heads -type f
# Solution: Initialize repository first
git-rs init
# Solution: Run commands from within repository root
cd /path/to/repository
git-rs status
# Solution: Check file/directory permissions
ls -la .git-rs/
chmod -R u+w .git-rs/
git status
and git-rs status
to see differences.git-rs/git-rs-index
as you add filesEach command in git-rs is designed to be educational first, functional second. The goal is to understand how Git works internally, not to replace Git for production use.