Progress:
TIER 3 · MODULE 21· Expert

git cat-file

The object-database microscope. Learn -p, -t, -s, --batch.

🎯 What & why

git cat-file is the object-database microscope: it reads any object (blob, tree, commit, tag) by SHA and tells you its type, size, or pretty-printed content. It's the first plumbing command everyone should learn because it makes Git's storage stop being magic.

🧠 Mental model

Git is a content-addressed key-value store; cat-file is the GET. Hand it a hash, ask -t (what kind), -s (how big), -p (show me), or -e (does it exist), and it answers from .git/objects.

🛠️ Synopsis

git cat-file (-t | -s | -e | -p) <object>
git cat-file <type> <object>
git cat-file --batch[=<format>] [--follow-symlinks]
git cat-file --batch-check[=<format>]
git cat-file --batch-all-objects [--batch | --batch-check] [--unordered]
git cat-file (--textconv | --filters) [<rev>:<path> | --path=<path> <object>]

🎚️ Switches & options

FlagWhat it does
-tPrint the object's type (blob, tree, commit, tag).
-sPrint the object's size in bytes.
-pPretty-print the object's contents based on type.
-eExit 0 if object exists and is valid; silent otherwise. Useful in scripts.
--batch[=<fmt>]Read object names on stdin, write info + content per line. Fast bulk inspection.
--batch-check[=<fmt>]Like --batch but only metadata, no content. Cheap existence/type probes.
--batch-all-objectsIterate every object in the repo (with --batch or --batch-check).
--filters / --textconvApply smudge filters / textconv for human-readable output of a path.

💡 Use cases

🧪 Examples

Pretty-print a commit
git cat-file -p HEAD
Get type of an object
git cat-file -t 4b825dc642cb6eb9a060e54bf8d69288fbee4904
Bulk-check all objects
git cat-file --batch-check --batch-all-objects | head
Read a file at a revision
git cat-file -p HEAD:README.md

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.