Git is the tool most developers use the most and understand the least. We memorise commands, and when something goes wrong we copy a fix from a search result. Yet the model underneath is small: a few kinds of objects, each named by the hash of its content, and some files that point at them. Once you see that model, checkout , branch and log stop being magic.
The best way I know to see it is to write it. mini-git is a small Git implementation in Rust that reads and writes real git loose objects : zlib-compressed and SHA-1 addressed. Its binary is called mgit . Repositories created by mgit can be opened by git , and mgit can read repositories created by git , as long as the objects are loose. This post covers what I built and what it teaches about Git.
What I built
The object format. object.rs implements the encoding every Git object uses: a header "<type> <len>\0" followed by the body.…