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.
git cat-file Syntax:
Section titled “git cat-file Syntax:”git cat-file <type> <object>git cat-file (-e | -p | -t | -s) <object>git cat-file (--textconv | --filters) [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects] [--buffer] [--follow-symlinks] [--unordered] [--textconv | --filters] [-Z]Options:
Section titled “Options:”| Option | Description |
|---|---|
| -t | Instead of the content, show the object type identified by |
| -s | Instead of the content, show the object size identified by |
| -e | Exit with zero status if |
| -p | Pretty-print the contents of |
| —[no-]mailmap, —[no-]use-mailmap | Use mailmap file to map author, committer and tagger names and email addresses |
| —textconv | Show the content as transformed by a textconv filter |
| —filters | Show the content as converted by the filters configured in the current working tree |
| —filter= | Omit 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-objects | Perform the requested batch operation on all objects in the repository |
| —buffer | Use normal stdio buffering; more efficient for processing many objects |
| —unordered | Visit objects in an unspecified order which may be more efficient |
| —follow-symlinks | Follow symlinks inside the repository when requesting objects with extended SHA-1 expressions |
| -Z | Use NUL-delimited input and output instead of newline-delimited |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| The name of the object to show | |
| Typically this matches the real type of |
git cat-file Command Samples:
Section titled “git cat-file Command Samples:”Show the type of an object
Section titled “Show the type of an object”git cat-file -t HEADGets the object type of the commit pointed to by HEAD.
Show the size of a blob object
Section titled “Show the size of a blob object”git cat-file -s HEAD:README.mdDisplays the size in bytes of the README.md file in the HEAD commit.
Pretty-print a commit object
Section titled “Pretty-print a commit object”git cat-file -p HEADDisplays the full commit information including author, date, message, and tree hash.
Check if an object exists
Section titled “Check if an object exists”git cat-file -e abc123Returns exit code 0 if object exists, non-zero otherwise.
Batch mode to process multiple objects
Section titled “Batch mode to process multiple objects”echo "HEAD^{tree}" | git cat-file --batchTakes object from stdin and outputs SHA, type, size, and contents.
Show content with filters applied
Section titled “Show content with filters applied”git cat-file --filters HEAD:script.pyShows 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:
git cat-file <type> <object>How can I check if a Git object exists?
Section titled “How can I check if a Git object exists?”To check if a Git object exists, run:
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:
git cat-file -t <object>How can I see the size of a Git object?
Section titled “How can I see the size of a Git object?”To see the size of a Git object, use:
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:
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:
echo "<object>" | git cat-file --batchApplications of the git cat-file command
Section titled “Applications of the git cat-file command”- Inspecting the raw contents of Git objects for debugging repository issues
- Checking object types and sizes to understand repository structure
- Pretty-printing commit, tree, and blob objects for analysis
- Validating object existence before processing in scripts
- Processing large numbers of objects efficiently in batch mode
- Applying text conversion filters to content during inspection
- Following symlinks within the repository structure