git cat-file

Updated November 1, 2026

A plumbing command for reading objects in .git/objects/ by their SHA. The main flags are: -t (type), -s (size), -p (content in human-readable form), -e (check whether the object exists).

git cat-file is the primary tool for inspecting the contents of Git objects from the inside. Use it in scripts, during debugging, and when learning how Git stores data.

Basic flags

git cat-file -t <sha>   # type: blob | tree | commit | tag
git cat-file -s <sha>   # content size in bytes
git cat-file -p <sha>   # content (pretty-print)
git cat-file -e <sha>   # existence check via exit code

Pretty-print adapts its formatting to the object type:

  • blob: raw bytes as-is.
  • tree: a table of "mode type sha name".
  • commit: text representation with tree, parent, author, committer, message.
  • tag: annotated tag with all fields.

Examples

What object is under this SHA?

git cat-file -t 8d0e41
# blob

Show the content of the latest commit:

git cat-file -p HEAD
# tree 7e3f9a2b1c4d5e6f...
# parent a1b2c3d4...
# author ...
# committer ...
#
# Commit message

Look inside the root tree of that commit:

git cat-file -p HEAD^{tree}
# 100644 blob 5f7e9c12...    README.md
# 100644 blob 8a3f2e91...    index.html

Check whether an object exists without any output:

if git cat-file -e <sha> 2>/dev/null; then
  echo "object is present"
fi

Batch mode

For scripts that read many objects at once:

echo HEAD | git cat-file --batch
# <sha> commit 245
# tree ...
# parent ...
# ...

--batch reads SHAs from stdin one per line and outputs the metadata plus content for each. On large repositories this is tens of times faster than calling cat-file -p for each SHA separately.

Pitfalls

  • Pretty-print for a blob outputs raw bytes as-is. If the blob is binary (an image, an archive), this will corrupt your terminal. Check the type with -t first.
  • An object may be in a packfile, and cat-file will find it regardless. This is the plumbing level; packfiles are transparent.
  • -p HEAD shows the commit object, not the tree. To see the directory contents, use HEAD^{tree} or git ls-tree HEAD.

Commands

  • git cat-file -t <sha>: Get the type of an object
  • git cat-file -p HEAD: Print a commit with its metadata
  • git cat-file -p HEAD^{tree}: Print the root tree of the commit
  • git cat-file -e <sha>: Check whether an object exists (exit code)

See also