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

Internal format of a git blob
blob {size} {binary data}

Git calculates the hashsum as

Calculation of the git hash for a file in Python
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: