The object-database microscope. Learn -p, -t, -s, --batch.
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.
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.
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>]| Flag | What it does |
|---|---|
-t | Print the object's type (blob, tree, commit, tag). |
-s | Print the object's size in bytes. |
-p | Pretty-print the object's contents based on type. |
-e | Exit 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-objects | Iterate every object in the repo (with --batch or --batch-check). |
--filters / --textconv | Apply smudge filters / textconv for human-readable output of a path. |
git cat-file -p HEADgit cat-file -t 4b825dc642cb6eb9a060e54bf8d69288fbee4904git cat-file --batch-check --batch-all-objects | headgit cat-file -p HEAD:README.mdHit each option, then Check answers. Score is recorded; Next is always open.