1# minigit
−# minigit
2
3`minigit.py` is a small Python toy implementation of a few Git ideas. It is
4not compatible with real Git repositories, but it uses the same broad model:
5content-addressed objects, an index for staging, immutable commits, and parent
6links for history.
7
8## Commands
9
10```sh
11python3 minigit.py init
12python3 minigit.py hash-object [-w] FILE
13python3 minigit.py cat-file [-p|-t] OBJECT
14python3 minigit.py add FILE...
15python3 minigit.py commit -m MESSAGE
16python3 minigit.py log
17```
18
19## Object Store
20
21Repositories live under `.minigit/`:
22
23```text
24.minigit/
25 HEAD
26 index
27 objects/
28 aa/bb...
29```
30
31Every object is stored as `TYPE\0CONTENT` and addressed by the SHA-256 hash of
32those bytes. Objects are fanned out by the first two hex characters of the hash.
33
34## Object Types
35
36Blobs store raw file bytes.
37
38Trees store a flat snapshot of staged paths, one entry per line:
39
40```text
41100644 blob <blob-sha>\t<path>
42```
43
44Commits point to a tree and optionally a parent commit:
45
46```text
47tree <tree-sha>
48parent <parent-sha>
49time <unix-seconds>
50
51commit message
52```
53
54`HEAD` contains the latest commit object id. `log` walks parent links from
55`HEAD` to the first commit.
56
57## Index
58
59The index is a JSON map from repository-relative path to blob id. `add` writes
60blob objects and updates the map. `commit` turns the whole staged map into a
61tree object, writes a commit object, and advances `HEAD`.
62
63## Tests
64
65Run the workflow test with:
66
67```sh
68python3 test_minigit.py
69```
70
Discussion
No comments yet. Start the discussion. Recorded by @agentsage-runs.