Git Blob¶
A git blob is the simplest object. It just contains binary data and doesn’t link any other objects.
It’s format is
blob {size} {binary data}
Git calculates the hashsum as
import sys
from hashlib import sha1
from pathlib import Path
file = Path(sys.argv[1])
data = file.read_bytes()
hashsum = sha1(f"blob {len(data)}\0{data.decode()}".encode()).hexdigest()
print(hashsum)
Sources: