linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Object model/blob

kb/objects ── Object model ── intermediate

Blob

A Git object that stores the content of a single file. Just bytes, no name, no permissions, no date. The filename lives in the `tree`, not in the blob.

view as markdownaka: git-blob, blob-object

Blob (binary large object) is the simplest of the four Git object types. It holds only the file's content as a sequence of bytes. It has no knowledge of the file's name or location.

The filename, permissions, and path all live in a tree object, which references the blob by its SHA.

Creating a blob

At the high-level API, blobs are created automatically on git add. With plumbing commands:

bash
echo "content" | git hash-object --stdin -w
# 8d0e41234f24b6da002d962a26c2495ea16a425f

The -w flag writes the blob to .git/objects/. Without it, Git only returns the SHA and writes nothing.

SHA-1 hash

The hash is computed not from the raw content but from this string:

blob <length-in-bytes>\0<content>

The blob prefix and the length are part of the data being hashed. That is why an empty file and a file containing one blank line have different SHAs: the lengths differ.

Deduplication

If two files in the repository are byte-for-byte identical, they share the same SHA, and Git stores one blob. At the tree level they appear as two separate entries (with different names), but both point to the same object in .git/objects/.

This gives you content-based deduplication for free: identical files do not consume space twice, even across different commits.

§ команды

bash
git hash-object --stdin -w

Create a blob from stdin and write it to objects/

bash
git cat-file -p <sha>

Print the raw content of a blob

bash
git cat-file -t <sha>

Show the object type (returns blob)

bash
git cat-file -s <sha>

Show the content size in bytes

§ см. также

  • treeTreeA Git object that holds the listing of one directory: entries of the form `(mode, type, SHA, name)`. It references other tree objects recursively for subdirectories.
  • commitCommitA Git object: a snapshot of the entire project (via a tree) plus metadata including author, committer, date, parents, and message. The SHA of a commit includes the parent's SHA, which makes history cryptographically linked.
  • sha1SHA-1 in GitThe 40-character hash Git uses to address objects. Computed from content with a type prefix. Broken cryptographically in 2017 (SHAttered), but still the default in Git as migration to SHA-256 moves slowly.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies