LinuxCommandLibrary

git-cat-file

Display Git object content

TLDR

Get the [s]ize of the HEAD commit in bytes

$ git cat-file -s HEAD
copy

Get the [t]ype (blob, tree, commit, tag) of a given Git object
$ git cat-file -t [8c442dc3]
copy

Pretty-[p]rint the contents of a given Git object based on its type
$ git cat-file -p [HEAD~2]
copy

SYNOPSIS

git cat-file [-t ] [-s ] [-e ] [-p ] [--batch | --batch-check[=] | --follow-symlinks] [--textconv] [--filters] [--path=] [--obj-name] [--allow-unknown-type] [--buffer-output] [--in-place] []

PARAMETERS

-t
    Show the object type (blob, tree, commit, tag).

-s
    Show the object size.

-e
    Exit with zero status if exists; otherwise, exit with non-zero status.

-p
    Pretty-print the object's content.

--batch
    Read objects from stdin, one per line.

--batch-check[=]
    Read objects from stdin and show info. allows customization of the output.

--follow-symlinks
    Follow symbolic links when examining tree entries.

--textconv
    Apply textconv filter.

--filters
    Apply object filters.

--path=
    Use to resolve path names.

--obj-name
    Show the object name instead of the content.

--allow-unknown-type
    Allow accessing objects of unknown types.

--buffer-output
    Buffer the output.

--in-place
    Operate on the given objects directly, instead of writing to standard output.


    The Git object (blob, tree, commit, tag) to inspect.

DESCRIPTION

The `git cat-file` command provides a Swiss-army knife for accessing the contents of Git repository objects. It allows you to view object data (blobs, trees, commits, tags) in different formats, verify their type, and even extract their size. Think of it as a low-level tool for directly interacting with the Git object database. It's primarily intended for scripting and internal Git operations rather than everyday user interaction. This command is useful for understanding the internal structure of a Git repository and for debugging purposes. It can also be leveraged to build other Git tools or scripts that require direct access to Git object data. You can use it to examine the contents of files stored in your repository, browse the directory structure represented by trees, and inspect the metadata associated with commits and tags. The versatility of `git cat-file` makes it a valuable tool for Git experts and developers.

OBJECT SPECIFICATION

Most Git tools pretty-print the information stored in the Git database in a human-readable way, but sometimes you need to peek inside and see the raw data. This command allows you to do just that, enabling direct examination of Git objects.

EXAMPLES

Example 1: Display the type of a commit object:
git cat-file -t HEAD

Example 2: Display the content of a blob object:
git cat-file -p

Example 3: Check if an object exists:
git cat-file -e

SEE ALSO

Copied to clipboard