Skip to content
BIASED
Back to topic

Optional

Object model: blob/tree/commit

From hashes rebuild commit→tree→blobs; explain why a rename is delete+add of content.

Version
v1
Minutes
~20
Evidence
Self-check in the notebook

Until platform auto-check exists, compare cell output with the expected numbers in the notebook. This is not a debt and does not affect mastery.

Download .ipynb

Download the notebook and run it locally. Its environment requirements are listed inside.

Notebook contents

Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.

DevOps · Объектная модель Git / Git object model counts

Activity version: 1 · Seed: n/a · Данные: два коммита из заметки курса.

Сценарий: README.md (Shop service\n) + src/app.py; второй коммит меняет только app.py. Неизменённый blob README переиспользуется.

Ожидаемые числа
Quantity Value Tolerance
blobs 3 exact
trees 4 exact
commits 2 exact
count-objects 9 exact
Самопроверка в ноутбуке

Не влияет на mastery.

import hashlib
 
def git_hash(kind: str, content: bytes) -> str:
    header = f"{kind} {len(content)}\0".encode()
    return hashlib.sha1(header + content).hexdigest()
 
readme = b"Shop service\n"
app_v1 = b"print('v1')\n"
app_v2 = b"print('v2')\n"
 
blob_readme = git_hash("blob", readme)
blob_app1 = git_hash("blob", app_v1)
blob_app2 = git_hash("blob", app_v2)
 
# Two commits × two trees each (root + src/) = 4 trees; README blob shared → 3 blobs; 2 commits.
n_blobs = len({blob_readme, blob_app1, blob_app2})
n_trees = 4
n_commits = 2
n_objects = n_blobs + n_trees + n_commits
 
print("blobs", n_blobs, "trees", n_trees, "commits", n_commits, "total", n_objects)
assert n_blobs == 3
assert n_trees == 4
assert n_commits == 2
assert n_objects == 9
assert blob_readme == git_hash("blob", b"Shop service\n")
print("OK: git object counts")
 
Самопроверка в ноутбуке
  • blobs = 3 (README shared)
  • trees = 4, commits = 2, total = 9