Skip to content

cat-file Git Command Guide

The git cat-file command is used to provide contents or details of repository objects, operating in two modes: non-batch mode for single object queries, and batch mode for processing multiple objects from standard input.

Terminal window
git cat-file <type> <object>
Terminal window
git cat-file (-e | -p | -t | -s) <object>
Terminal window
git cat-file (--textconv | --filters)
[<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
Terminal window
git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects]
[--buffer] [--follow-symlinks] [--unordered]
[--textconv | --filters] [-Z]
OptionDescription
-tInstead of the content, show the object type identified by
-sInstead of the content, show the object size identified by
-eExit with zero status if exists and is a valid object
-pPretty-print the contents of based on its type
—[no-]mailmap, —[no-]use-mailmapUse mailmap file to map author, committer and tagger names and email addresses
—textconvShow the content as transformed by a textconv filter
—filtersShow the content as converted by the filters configured in the current working tree
—filter=, —no-filterOmit objects from the list of printed objects (batch modes only)
—path=For use with —textconv or —filters, to allow specifying an object name and a path separately
—batch, —batch=Print object information and contents for each object provided on stdin
—batch-check, —batch-check=Print object information for each object provided on stdin
—batch-command, —batch-command=Enter a command mode that reads commands and arguments from stdin
—batch-all-objectsPerform the requested batch operation on all objects in the repository
—bufferUse normal stdio buffering; more efficient for processing many objects
—unorderedVisit objects in an unspecified order which may be more efficient
—follow-symlinksFollow symlinks inside the repository when requesting objects with extended SHA-1 expressions
-ZUse NUL-delimited input and output instead of newline-delimited
ParameterDescription
The name of the object to show
Typically this matches the real type of but asking for a type that can trivially be dereferenced is also permitted
Terminal window
git cat-file -t HEAD

Gets the object type of the commit pointed to by HEAD.

Terminal window
git cat-file -s HEAD:README.md

Displays the size in bytes of the README.md file in the HEAD commit.

Terminal window
git cat-file -p HEAD

Displays the full commit information including author, date, message, and tree hash.

Terminal window
git cat-file -e abc123

Returns exit code 0 if object exists, non-zero otherwise.

Terminal window
echo "HEAD^{tree}" | git cat-file --batch

Takes object from stdin and outputs SHA, type, size, and contents.

Terminal window
git cat-file --filters HEAD:script.py

Shows the content of script.py from HEAD after applying configured filters.

How do I view the raw content of a Git object?

Section titled “How do I view the raw content of a Git object?”

To view the raw content of a Git object, use:

Terminal window
git cat-file <type> <object>

To check if a Git object exists, run:

Terminal window
git cat-file -e <object>

How do I display the type of a Git object?

Section titled “How do I display the type of a Git object?”

To display the type of a Git object, execute:

Terminal window
git cat-file -t <object>

To see the size of a Git object, use:

Terminal window
git cat-file -s <object>

How do I pretty-print Git object contents?

Section titled “How do I pretty-print Git object contents?”

To pretty-print Git object contents, run:

Terminal window
git cat-file -p <object>

How can I process multiple objects in batch mode?

Section titled “How can I process multiple objects in batch mode?”

To process multiple objects in batch mode, use:

Terminal window
echo "<object>" | git cat-file --batch
  1. Inspecting the raw contents of Git objects for debugging repository issues
  2. Checking object types and sizes to understand repository structure
  3. Pretty-printing commit, tree, and blob objects for analysis
  4. Validating object existence before processing in scripts
  5. Processing large numbers of objects efficiently in batch mode
  6. Applying text conversion filters to content during inspection
  7. Following symlinks within the repository structure