git-cat-file
Display Git object content
TLDR
Get the [s]ize of the HEAD commit in bytes
Get the [t]ype (blob, tree, commit, tag) of a given Git object
Pretty-[p]rint the contents of a given Git object based on its type
SYNOPSIS
git cat-file [-t|-s|-p|-e]
PARAMETERS
-t, --type
Print the object's type (blob, tree, commit, tag)
-s, --size
Print the object's size in bytes
-p, --pretty-print
Pretty-print object contents in human-readable format
-e, --allow-empty
Exit 0 if object exists (even empty blob), else 1
--batch[=format]
Read objects from stdin and print formatted output
--batch-check[=format]
Read objects from stdin and print metadata only
--batch-all-objects
Process all loose objects in batch-check mode
--buffer
Buffer output in batch mode before printing
--textconv
Apply textconv filters to blobs in batch mode
--filters
Apply smudge/clean filters to blobs in batch mode
-z
Use NUL as delimiter instead of newline in batch modes
DESCRIPTION
git cat-file is a low-level plumbing command in Git for inspecting and displaying repository objects such as blobs, trees, commits, and tags. It retrieves objects by their SHA-1 hash from the .git/objects directory and can show the object's type, size, or formatted content.
Common uses include debugging Git internals, scripting repository analysis, verifying object integrity, or extracting data without checking out files. For human-readable output, use -p to pretty-print: blobs show file contents, commits display headers and messages, trees list entries, and tags show annotations.
Batch modes enable efficient processing of multiple objects from stdin, ideal for tools parsing large repositories. It supports custom output formats, filters for textconv, and delta decompression. Unlike porcelain commands like git show, it lacks high-level features but offers precise control for developers and scripts.
CAVEATS
Plumbing command for scripts; output format may change. Requires valid object hash. Batch modes expect specific stdin format: hex-sha1 + LF + object size + LF + data.
BATCH INPUT FORMAT
stdin lines: <hex-sha1>
<size>
object data
(repeat)
EXIT CODES
0: success/object exists; 1: object missing/unreadable; 128: usage error; 130: interrupted
HISTORY
Introduced in Git 1.4.0 (2006) as core plumbing; batch modes added in 1.6.0 (2008), enhanced with formats in 2.8.0 (2016). Evolved for efficient repo inspection.
SEE ALSO
git show(1), git ls-tree(1), git rev-parse(1), git hash-object(1)


