git cat-file: Usage, Options & Common CI Errors
git cat-file is the plumbing that reveals the type, size, and content of any Git object.
cat-file is the low-level lens on the object store - useful for scripts that verify objects exist or read blob contents.
What it does
git cat-file reads objects from the database and prints their type, size, or pretty-printed content. It is the canonical way to verify an object exists and inspect commits, trees, and blobs.
Common usage
Terminal
git cat-file -t HEAD # object type (commit)
git cat-file -s <sha> # size in bytes
git cat-file -p HEAD # pretty-print the object
git cat-file -p HEAD:path/file # a blob's contents
git cat-file -e <sha> && echo existsOptions
| Flag | What it does |
|---|---|
| -t | Print the object type |
| -s | Print the object size |
| -p | Pretty-print the object content |
| -e | Exit 0 if the object exists (no output) |
| --batch / --batch-check | Stream many objects efficiently |
Common errors in CI
fatal: Not a valid object name <sha> or fatal: git cat-file <sha>: bad file - the object is absent (truncated SHA or a shallow clone missing it). Use -e to test existence first, and ensure full history is present for deep object lookups.
Related guides
git show: Usage, Options & Common CI Errorsgit show displays a commit, tag, or object with its diff. Reference for --stat, --name-only, blob viewing, an…
git rev-parse: Usage, Options & Common CI Errorsgit rev-parse resolves refs to SHAs and reports repo paths - core CI plumbing. Reference for --short, --abbre…
git fsck: Usage, Options & Common CI Errorsgit fsck verifies object-database integrity and finds dangling or corrupt objects. Reference for --full, --lo…
git ls-files: Usage, Options & Common CI Errorsgit ls-files lists files Git knows about in the index. Reference for --others, --modified, --exclude-standard…