• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

git cat-file: Provide content or type and size information for Git repository objects

by admin

The git cat-file command is a versatile Git command that allows you to retrieve information about Git objects in a repository. It provides you with the ability to access and display the content, type, and size of Git objects such as commits, trees, blobs, and tags.

The basic syntax of the git cat-file command is as follows:

#  git cat-file [-t | -s | -p] [object]

Here’s what each option does:

  • -t: Displays the type of the object.
  • -s: Displays the size of the object.
  • -p: Displays the content of the object.

The [object] argument refers to the Git object you want to examine. It can be specified using its SHA-1 hash, a branch name, a tag name, or a reference.

When you run git cat-file with the -t option, it will output the type of the object. For example, if you want to know the type of a commit object with the SHA-1 hash abcdef12345, you would run:

# git cat-file -t abcdef12345

The command will output commit, indicating that the object is a commit.

Using the -s option, you can retrieve the size of the object. This can be useful for understanding the size of individual objects in the repository. For example:

# git cat-file -s abcdef12345

This command will display the size of the object with the SHA-1 hash abcdef12345.

Finally, the -p option allows you to view the content of the object. The content will be displayed based on the type of the object. For example, to view the content of a blob object, you can run:

# git cat-file -p abcdef12345

This will show the contents of the blob object with the SHA-1 hash abcdef12345.

The git cat-file command is a useful tool for inspecting and extracting information from Git objects. It provides you with a low-level view of the objects in your repository, enabling you to understand and analyze the structure and contents of your Git data.

git cat-file Command Examples

1. Get the [s]ize of the HEAD commit in bytes:

# git cat-file -s HEAD

2. Get the [t]ype (blob, tree, commit, tag) of a given Git object:

# git cat-file -t 8c442dc3

3. Pretty-[p]rint the contents of a given Git object based on its type:

# git cat-file -p HEAD~2

Filed Under: Linux

Some more articles you might also be interested in …

  1. clang: Compiler for C, C++, and Objective-C source files. Can be used as a drop-in replacement for GCC
  2. UbuntuDDE new upcoming Linux distribution
  3. gnome-screenshot Command Examples in Linux
  4. Backtick (`) symbol in Linux Shell Scripting
  5. apt-key: command not found
  6. insmod: command not found
  7. btrbk: command not found
  8. How to uninstall postgresql-client-common software package in Ubuntu
  9. rkhunter Command Examples in Linux
  10. “hg server” Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright