gitcat

What does `cat-file` stand for in git?


In git, what does cat-file stand for in this command?

$ git cat-file <...>

My first thought is "concatenate file" because the Unix command cat stands for "concatenate", but this doesn't correspond to the function of git cat-file.


Solution

  • While cat does stand for "concatenate", what it actually does is simply display one or multiple files, in order of their appearance in the command line arguments to cat. The common pattern to view the contents of a file on Linux or *nix systems is:

    cat <file>
    

    The main difference between cat and Git's cat-file is that it only displays a single file (hence the -file part). Git's cat-file doesn't really stand for "concatenate"; it simply is a reference to the behavior of the cat command.

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

    Technically, you can use git cat-file to concatenate files, if you use Batch Output mode:

    BATCH OUTPUT

    If --batch or --batch-check is given, cat-file will read objects from stdin, one per line, and print information about them. By default, the whole line is considered as an object, as if it were fed to git-rev-parse[1].