Team Blaze Β· DSCPP-III-2026-T296 Β· CSE (AI&ML)
Department of Computer Science & Engineering β Graphic Era (Deemed to be University)
MiniGit is a lightweight, local, terminal-based version control system implemented in C++. Designed as an educational version control system, MiniGit demystifies core VCS conceptsβrepository initialization, staging areas, ignore rule management, and commit workflowsβwhile directly applying foundational computer science data structures such as Tries (Prefix Trees), an ordered set, a double-ended queue (undo/redo), a doubly linked list (commit log) and a directed acyclic graph (commits and branches).
MiniGit follows a modular 5-layer architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. CLI Interface & Argument Parser β
β (Tokenizes input, validates flags: -r, -v, ., etc.) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 2. Command Handler & Dispatcher (Abhinesh's Module) β
β (Maps commands -> operations; handles status codes) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 3. Repository & Staging Manager β
β (.minigit/ structure, index persistence, undo/redo) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 4. Ignore Engine (Trie Data Structure) β
β (Dual Prefix Trees: Path Trie & Reversed Ext Trie) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 5. Storage Layer (File I/O) β
β (.minigit/objects, .minigit/index, .minigit/HEAD) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
minigit init: Creates.minigit/(objects/,refs/heads/,HEAD=ref: refs/heads/main,index) and.minigitignore. Re-running it never overwrites existing data, and every failed write is reported.- Table-Driven Command Dispatcher: One table row per command holds its name, aliases, usage forms and handler.
minigit help,minigit help <command>,minigit <command> --helpand the usage printed on wrong arguments are all generated from it, so they cannot go out of date. - Typo Suggestions: An unknown command is matched to the closest real one by Levenshtein edit distance (
minigit comitβ The most similar command is commit). - Status & Error Mapper: Turns result structs (
InitResult,AddResult,IgnoreResult,CommitResult,LogResult) into messages and exit codes (0 = success, 1 = error). - Ignore CLI Interface: Validates
ignore,ignore -randignore -vinput; rejects empty patterns and anything outside the repository (.., absolute paths, drive letters). - First-Run Self-Installation: Copies the executable into the user's
PATHon first run, and refreshes that copy when a newer build is run.
-
Dual-Trie Ignore Engine: A forward Trie handles file paths and directory rules, while a reversed Trie handles extension patterns such as
*.cpp, giving$O(L)$ matching without scanning the disk. -
.minigitignoreManagement: Supports adding, removing and evaluating rules throughignore,ignore -randignore -v. Stores the line number of each rule, tolerates CRLF line endings, and always excludes the internal.minigit/directory. -
Path & Directory Matching: Handles exact paths, directory-prefix rules and extensions, and enforces directory boundaries so
build/does not matchbuildings/. -
Staging Area (
.minigit/index): Keeps normalized repository-relative paths in astd::setto prevent duplicates, with persistent storage and unstaging throughremove <file|dir|.>. -
Recursive Add:
add <file|dir>andadd .walk directories recursively, check ignore rules before staging, and skip ignored directories entirely. -
Testing:
test_trieandtest_addcover Trie operations, extension patterns, directory boundaries, duplicate staging, rule removal and CRLF handling.
-
minigit commit: Saves each staged file's content under.minigit/objects/<id>/snapshot/, writesmetadata(parent, timestamp, author, message, files) and movesHEAD. The commit id is a SHA-1 of that content. -
Undo / Redo (
std::deque): Two deques of repository states. A new commit clears the redo deque; the undo deque is capped at 20 entries withpop_front(). Persisted in.minigit/history. -
Reset-Style Rollback (
minigit rollback <commit-id>): Rolls back the currently active branch to any historical commit and restores its exact working-tree snapshot while preserving all subsequent commit objects. -
DAG Commit Graph (
CommitGraph): Models commits as vertices, directed edges from children to parents, and branch references as named pointers to commit nodes. Supports shared ancestors, independent diverging histories, and cycle detection. -
Branch Management (
minigit branch,minigit checkout <branch>): Lightweight branching via references stored in.minigit/refs/heads/. Fast context switching with working directory snapshot reconciliation and uncommitted change protection. -
Graph Visualization (
minigit log --all --graph): Renders full repository commit history and branch divergence in an ASCII DAG tree.
minigit log: Rebuilds the history fromHEADby following parent links into a doubly linked list, then walks it backward (newest first) or forward with--reverse.minigit checkout <commit-id>: Restores the files of any saved commit (full id or a unique prefix of 4+ characters) and leavesHEADdetached at it, so no branch moves. Unsaved work (staged, edited or deleted tracked files, untracked files in the way) is checked first and makes it refuse without changing anything. Files are written to temporary copies first and swapped in with backups, so a failure part-way rolls everything back. Ignored files are never touched.- Commit List (
CommitNode,CommitLog): Each node holds the commit id, parent, message, timestamp and files, and links to the older and newer commit. The list supportsinsert,find,nextandprev; loading it from disk uses a visited set, so a damaged parent cycle cannot loop forever. - Testing:
test_commitlog(the list alone),test_log(log/log --reverseover real commits, after undo, on an empty repository) andtest_checkout(restore, refusal, ignored files, detached-HEAD rules). - Detached HEAD:
log,branchandcheckout <branch>work there.commit,undo,redoandrollbackrefuse, because they move a branch;minigit branch <name>thenminigit checkout <name>continues from that commit.
Used for instant, deterministic pattern matching to block ignored files from staging:
-
Forward Path Trie: Stores exact file paths (
secret.txt) and directory rules (build/). Traverses path tokens in$O(L)$ time. -
Reversed Extension Trie: Stores wildcard extension patterns (e.g.
*.logis stored as reversed keygol.). When evaluating a filename, its reversed extension is queried in$O(E)$ time. -
Line Number Indexing: Every terminal Trie node stores the 1-based line number of the matching rule from
.minigitignore, allowing instant rule tracking during verification.
- Maintains staged file paths in
.minigit/index(one path per line). - Held in memory as
std::set(a red-black tree):$O(\log n)$ duplicate staging prevention and status checks, and entries stay sorted so the index file has a stable order.
-
std::dequegives$O(1)$ push_back/pop_backfor undo and redo, and$O(1)$ pop_frontto drop the oldest state once the 20-entry history limit is reached.
- Each
CommitNodelinks to the older and newer commit, sologandlog --reverseare both a single$O(n)$ walk from one end of the list.
CommitGraphmodels commits as vertices stored in an adjacency list usingstd::unordered_map<std::string, CommitGraphNode>.- Directed edges maintain parent-child relationships across diverging branches and common ancestors.
- Cycle detection is performed via 3-color DFS to guarantee DAG properties.
- Topological sorting (Kahn's algorithm) orders commits so that children precede parents, enabling ASCII rendering (
log --all --graph).
| Command | Action / Dispatcher Function | Description |
|---|---|---|
minigit init |
initRepo() |
Initializes a local repository structure (.minigit/, HEAD, refs/heads/, index) |
minigit add <file|dir> |
addFile(path) |
Stages a file, or every non-ignored file in a directory |
minigit add . |
addAll() |
Recursively stages all unignored files in the repository |
minigit add -v <file> |
addVerify(path) |
Verifies if file is staged (prints '<file>' is staged via IS_STAGED) |
minigit remove <file|dir> |
removeFile(path) |
Unstages a file, or every staged file in a directory, without touching the working tree |
minigit remove . |
removeFile(".") |
Clears all staged files from the staging area |
minigit ignore |
IgnoreManager::lines() |
Lists the rules in .minigitignore with line numbers |
minigit ignore <pattern> |
ignoreAdd(pattern) |
Validates and appends <pattern> to .minigitignore and updates the Trie |
minigit ignore -r <pattern> |
ignoreRemove(pattern) |
Removes <pattern> from .minigitignore (or reports "not present") |
minigit ignore -v <path> |
ignoreVerify(path) |
Checks if <path> is ignored; returns exact rule and line number |
minigit commit "<message>" / commit -m "<message>" |
commitRepo(message) |
Records the staged files as a new commit and clears the index |
minigit commit undo / undo |
undoCommit() |
Moves HEAD back one commit and restores its staged files |
minigit commit redo / redo |
redoCommit() |
Re-applies the last undone commit |
minigit rollback <commit-id> [--force] |
rollbackRepo(id, force) |
Reset-style rollback: moves active branch to target commit, restores exact snapshot, preserves subsequent commits |
minigit branch |
listBranches() |
Lists all branches (* indicates active branch, with tip commit IDs) |
minigit branch <branch-name> |
createBranch(name) |
Creates a new branch pointing to current HEAD commit without duplicating objects |
minigit branch -d <branch-name> |
deleteBranch(name) |
Deletes a branch reference (active branch cannot be deleted) |
minigit checkout <branch-name> [--force] |
checkoutBranch(name, force) |
Switches active branch, updates HEAD, and restores tracked files from snapshot |
minigit checkout <commit-id> |
checkoutCommit(id) |
Restores a saved commit's files and detaches HEAD at it (an existing branch of the same name wins) |
minigit log [--reverse] |
showLog(reverse) |
Shows commit history of active branch, newest first (oldest first with --reverse) |
minigit log --all --graph |
showLogGraph(all) |
Displays ASCII commit DAG showing branches and diverging histories |
minigit help [<command>] |
command table | Lists every command, or the usage of one (minigit <command> --help also works) |
minigit install |
CLI::install() |
Manually copies minigit into the user's PATH |
minigit uninstall |
CLI::uninstall() |
Removes minigit from user PATH |
add copies nothing; it only records normalized relative paths in .minigit/index. Ignore rules are checked first, and ignored directories are skipped without being walked.
minigit add main.cpp # Staged 'main.cpp'
minigit add src # staged 3 file(s), 0 already staged, skipped 0 ignored
minigit add . # staged 2 file(s), 3 already staged, skipped 1 ignored
minigit add secret.txt # 'secret.txt' is ignored by 'secret.txt' (line 2)
minigit add -v main.cpp # 'main.cpp' is stagedStaging a file twice never creates a duplicate entry, and a path that does not exist is reported as '<path>' does not exist.
remove only edits the index. Your working files are never touched.
minigit remove main.cpp # Unstaged 'main.cpp'
minigit remove src # Unstaged 3 files
minigit remove . # Unstaged 5 files (clears the whole staging area)
minigit remove notes.txt # 'notes.txt' is not stagedIf a staged file was deleted from disk, add records that as a staged deletion (Staged deletion of '<file>'), so the next commit removes it from the snapshot.
Rules live in .minigitignore, one per line. # starts a comment. Three rule types are supported:
| Rule | Example | Matches |
|---|---|---|
| Extension | *.log |
Any file ending in .log, at any depth |
| File path | secret.txt |
That exact path |
| Directory | build/ |
Everything under build/, but not buildings/ |
Negation (!keep.txt) and other wildcards (a/*.txt) are rejected with a clear message instead of being silently ignored. .minigit/ is always excluded.
minigit ignore # lists rules: 1: *.log 2: build/
minigit ignore "*.tmp" # Ignored '*.tmp' (line 3)
minigit ignore -v build/x.o # 'build/x.o' is ignored by 'build/' (line 2)
minigit ignore -v main.cpp # 'main.cpp' is not ignored
minigit ignore -r "*.tmp" # Removed '*.tmp' (was line 3)Removing a rule shifts later line numbers up, and the Tries are rebuilt so ignore -v always reports the correct line.
- Compiler:
g++(GCC 6.3+ or modern Clang/MSVC, supports C++14/C++17) - Build Tool: GNU
makeormingw32-make
From the repository root:
# Compile standalone executable minigit
make allThe project includes automated test suites covering all modules:
# Run all unit tests
make testTest coverage includes:
test_trie: Forward/reversed Trie pattern matching, wildcard extensions, and node pruning.test_add: Staging, duplicate prevention, ignore enforcement, and persistence.test_init: Repository creation, metadata structure, and reinitialization handling.test_cli: Full CLI dispatching, argument validation, generated help, typo suggestions, and theIS_STAGEDprint case.test_commit: Commit ids and metadata, snapshots, undo/redo and the history limit, multi-line messages.test_commitlog: The doubly linked list on its own (insert, find, cursor movement).test_log:log/log --reverseover real commits, after undo, and through the CLI.test_rollback: Reset-style rollback, file snapshot restoration, post-target file cleanup, object preservation, parent pointer continuity, staged and dirty-tree safety checks.test_branch: Branch listing, creation, switching, deletion, active-branch protection, and snapshot reconciliation across branches.test_checkout:checkout <commit-id>: exact restore, unsaved-work refusal, ignored files untouched, deletions honoured, detached-HEAD rules, damaged or unsafe commits rejected without changes.test_dag: 5-node diverging graph (A -> B/C -> D/E), shared ancestor verification, cycle detection, topological ordering, duplicate-free traversal, and ASCII graph rendering.test_pathutils:normalizePathspellings and trailing slashes,isOutsideRepo, andisSafeRepoPath(parent-directory escapes, absolute paths, drive letters,.minigit/internals).test_commithistory: The undo/redo deques on their own: undo and redo order, a new operation clearing redo, the 20-entry limit dropping the oldest entry,.minigit/historysave and load, older history files, and damaged files being discarded.test_fileutils:writeFileAtomicreplaces the whole file, keeps binary content as is, ignores a stale temporary file, and leaves nothing behind when it fails.test_staging: Staging, unstaging and staged deletions, sorted output, thedeleted:<path>index format, save and reload, and unsafe or blank index lines being dropped.test_repoutils: HEAD parsing (branch, detached, damaged), branch reference helpers, commit metadata parsing and rejection of damaged files, commit id prefix resolution, and the parent-chain walk (overrides, deletions, missing parents, cycles).test_regression: One numbered case (E001...E015) per defect that was found and fixed, so none of them can return unnoticed.test_integration: End-to-end scenarios (A-F) that drive the real dispatcher acrossinit,add,commit, branches, rollback and restarts, and check that files, refs and the DAG stay consistent.
make cleanBy default, PowerShell and Unix terminals restrict running local executables without prefixing .\ or ./.
MiniGit includes built-in zero-config self-installation:
- The first time
.\minigitis run on a Windows 10/11 system, it automatically copies itself into%LOCALAPPDATA%\Microsoft\WindowsApps\minigit.exe. - Because this directory is already in the user's
PATHby default and requires no administrator privileges, you can immediately run:from any folder or terminal window on your machine.minigit init minigit add . minigit ignore -v secret.txt
sample_repo/ holds a small notes project and a script that runs every command on a copy of it, one step at a time:
powershell -ExecutionPolicy Bypass -File sample_repo\walkthrough.ps1See sample_repo/README.md for what each step shows.
- DOCUMENTATION.md: design notes for every module and command.
- docs/REPOSITORY_FORMAT.md: the exact on-disk format of
.minigit/(HEAD, refs, index, commit objects, history, ignore rules). - CONTRIBUTING.md: how to build, test, name branches and write commits and code for this project.
- CHANGELOG.md: what changed in each project phase.
MiniGit/
βββ .gitignore # Ignores build artifacts, temporary test files, and local repo state
βββ LICENSE # MIT License
βββ Makefile # Top-level build orchestration
βββ README.md # Project documentation
βββ Reports/ # Phase evaluation documentation
β βββ report.pdf # Phase-I project proposal & architecture report
β βββ ppt.pdf # Phase-I presentation slides
β βββ phase2.pdf # Phase-II progress report
β βββ phase2-ppt.pdf # Phase-II presentation slides
β βββ phase3.pdf # Phase-III final report
β βββ phase3-ppt.pdf # Phase-III presentation slides
βββ sample_repo/ # Demo project and walkthrough.ps1 (see its README)
βββ module/ # Core source code & unit tests
βββ Makefile # Module compilation and test runners
βββ include/ # Header declarations
β βββ AddCommand.h # add / add . / add -v / remove interface
β βββ BranchCommand.h # branch / checkout interface
β βββ CLI.h # CLI parser, dispatcher, and status mapper
β βββ CommitCommand.h # commit / undo / redo interface
β βββ CommitGraph.h # DAG commit graph architecture
β βββ CommitHistory.h # Undo/redo deques (.minigit/history)
β βββ CommitLog.h # Doubly linked list over commits
β βββ CommitNode.h # One commit (list node)
β βββ FileUtils.h # Atomic file replacement (writeFileAtomic)
β βββ IgnoreManager.h # .minigitignore parser & Trie bridge
β βββ InitCommand.h # initRepo interface
β βββ LogCommand.h # log / log --reverse / log --all --graph interface
β βββ PathUtils.h # Path normalization & safety utilities
β βββ RepoUtils.h # Shared repository, snapshot, and ref utilities
β βββ RestoreCommand.h # checkout <commit-id> interface
β βββ RollbackCommand.h # Dedicated reset-style rollback interface
β βββ StagingArea.h # .minigit/index persistence manager
β βββ Trie.h # Pure Prefix Tree data structure
β βββ filesystem # Cross-compiler filesystem wrapper
β βββ ghc/ # Header-only standard filesystem implementation
βββ src/ # Implementation files
β βββ AddCommand.cpp
β βββ BranchCommand.cpp # Branch creation, deletion, and switching
β βββ CLI.cpp # Command table, dispatcher and output
β βββ CommitCommand.cpp
β βββ CommitGraph.cpp # DAG traversal, cycle detection, topological sort, ASCII graph
β βββ CommitHistory.cpp
β βββ CommitLog.cpp
β βββ IgnoreManager.cpp
β βββ InitCommand.cpp
β βββ LogCommand.cpp
β βββ RestoreCommand.cpp # checkout <commit-id>: transactional restore, detached HEAD
β βββ RollbackCommand.cpp # Rollback logic and file snapshot restoration
β βββ StagingArea.cpp
β βββ Trie.cpp
β βββ main.cpp # Production CLI entry point
β βββ main_demo.cpp # Standalone demo interface (add/ignore)
β βββ main_demo_log.cpp # Standalone demo interface (log)
βββ tests/ # Automated unit tests
βββ test_add.cpp
βββ test_branch.cpp # Branch management and switching tests
βββ test_checkout.cpp # checkout <commit-id> and detached HEAD tests
βββ test_cli.cpp
βββ test_commit.cpp
βββ test_commithistory.cpp # Undo/redo deques and .minigit/history
βββ test_commitlog.cpp
βββ test_dag.cpp # DAG structure, shared ancestors, cycle detection
βββ test_common.h # Shared CHECK macro and CLI-capture helpers
βββ test_fileutils.cpp # Atomic file replacement
βββ test_init.cpp
βββ test_integration.cpp # End-to-end scenarios A-F
βββ test_log.cpp
βββ test_pathutils.cpp # Path normalization and repository-escape checks
βββ test_repoutils.cpp # HEAD, commit metadata and history-walk helpers
βββ test_regression.cpp # One case per fixed defect (E001-E015)
βββ test_rollback.cpp # Rollback verification across scenarios
βββ test_staging.cpp # Staging area and index file
βββ test_trie.cpp
MiniGit is released under the MIT License.