⑂ minigit

A Git-like VCS, written from scratch

minigit.

SHA-1 by hand. A Merkle tree for every directory. A DAG for history. An LCS table and Myers' algorithm for diffs. A BFS merge-base for three-way merges. C++17 and the standard library, nothing else.

C++17 SHA-1 from scratch Content-addressable objects Huffman compression GoogleTest

History is a graph

A real snapshot from minigit export. Every node is a commit, every edge a parent pointer. Click a commit to inspect it.

Diff, live

The same two algorithms the CLI uses, ported to JavaScript for this page. LCS builds an n × m DP table; Myers walks diagonals and stays cheap for small changes.


      

Architecture

Small modules, one job each, wired together by a repository facade.

hash/

SHA-1 padding and block processing, plus the Huffman codec used for object storage.

sha1.cpp · huffman.cpp

objects/

Blobs, trees and commits with a sharded, content-addressed store. Trees are sorted, so equal directories produce equal ids.

object_store.cpp · tree.cpp · commit.cpp

repo/

Index, HEAD and refs, Merkle tree construction, branch checkout, history walking and merge orchestration.

repository.cpp · history.cpp · ignore.cpp

diff/

LCS dynamic programming, Myers greedy diff and unified hunk rendering with context merging.

lcs.cpp · myers.cpp · unified.cpp

merge/

Two BFS passes for the merge base, then a line-level three-way merge that emits conflict markers.

lca.cpp · three_way.cpp

cli/

Command parsing, git-style output and the ASCII DAG renderer with lanes and merge connectors.

main.cpp · graph.cpp

The on-disk format

.minigit/
  HEAD                    ref: refs/heads/main
  index                   <object-id> <path>
  objects/ab/cdef…        Huffman-compressed objects, sharded by 2 hex chars
  refs/heads/main         commit id

object  = "<type> <size>\0<payload>"
blob    = file bytes
tree    = "100644 blob <id> name\n" per entry
commit  = tree + parents + author + timestamp + message

Command line

Eight commands, one binary, no dependencies.

CommandWhat it does
initCreate the object store, HEAD and refs
add <path>…Hash files into blobs and stage them
commit -m "msg"Write trees + a commit and advance the branch
statusStaged, unstaged and untracked changes
log [--graph]Walk the DAG, plain or as ASCII lanes
branch [name]List branches or create one at HEAD
checkout <rev>Switch branch or detach at a commit
diff [--staged] [--myers]Unified diff via LCS or Myers
merge <branch>Fast-forward or three-way merge with conflicts
exportJSON snapshot that powers this page