Cat File

What

git cat-file is a powerful plumbing command used to inspect the type, size, and decompressed content of any object stored in the Git database.

How

You can pretty-print the content of any object (such as a commit, tree, or blob) by passing the -p flag followed by the unique commit hash:

# Pretty-print the content of a commit object
git cat-file -p 5ba786fcc93e8092831c01e71444b9baa2228a4f

You can also use flags to check the object type or size:

  • -t: Returns the object type (e.g., commit, tree, blob).
  • -s: Returns the object size in bytes.
# Check type of an object
git cat-file -t 5ba786f
# Output: commit

Why

Because Git objects are heavily compressed on disk, you cannot inspect their internal structure using standard shell commands. git cat-file is the primary debugging tool that allows you to bypass the user interface (porcelain) and peek directly into the exact data structure Git uses to represent commits and files.

Summary

Use the git cat-file -p <hash> plumbing command to decompress and view the raw content and metadata of any object in your Git repository.