IT系/リファレンス/Gitコマンド/git_cat-file

Last-modified: 2020-06-01 (月) 01:04:03

git cat-file

リポジトリオブジェクトの内容や種類、サイズ情報を提供するコマンド。

用例

  • mybranchブランチのdir/file.txtを閲覧する
    git cat-file -p mybranch:dir/file.txt
  • タグtagA中のファイルを閲覧
    git cat-file -p tagA:dir/file.txt
  • コミット"xxxx"中のファイルを閲覧
    git cat-file -p xxxx:dir/file.txt
  • HEADのひとつ前のコミット中のファイルを閲覧
    git cat-file -p HEAD^:dir/file.txt
  • オブジェクトのタイプを表示
    git cat-file -t hogeobject

書式

git cat-file [options] <object>

公式によると以下の通り。

git cat-file (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | <type> | --textconv | --filters ) [--path=<path>] <object>
git cat-file (--batch | --batch-check) [ --textconv | --filters ] [--follow-symlinks]

options

<object>The name of the object to show. For a more complete list of ways to spell object names, see the "SPECIFYING REVISIONS" section in gitrevisions.
-tInstead of the content, show the object type identified by <object>.
-sInstead of the content, show the object size identified by <object>.
-eExit with zero status if <object> exists and is a valid object. If <object> is of an invalid format exit with non-zero and emits an error on stderr.
-pPretty-print the contents of <object> based on its type.
<type>Typically this matches the real type of <object> but asking for a type that can trivially be dereferenced from the given <object> is also permitted. An example is to ask for a "tree" with <object> being a commit object that contains it, or to ask for a "blob" with <object> being a tag object that points at it.
--textconvShow the content as transformed by a textconv filter. In this case, <object> has to be of the form <tree-ish>:<path>, or :<path> in order to apply the filter to the content recorded in the index at <path>.
--filtersShow the content as converted by the filters configured in the current working tree for the given <path> (i.e. smudge filters, end-of-line conversion, etc). In this case, <object> has to be of the form <tree-ish>:<path>, or :<path>.
--path=<path>For use with --textconv or --filters, to allow specifying an object name and a path separately, e.g. when it is difficult to figure out the revision from which the blob came.
--batch | --batch=<format>Print object information and contents for each object provided on stdin. May not be combined with any other options or arguments except --textconv or --filters, in which case the input lines also need to specify the path, separated by whitespace. See the section BATCH OUTPUT below for details.
--batch-check | --batch-check=<format>Print object information for each object provided on stdin. May not be combined with any other options or arguments except --textconv or --filters, in which case the input lines also need to specify the path, separated by whitespace. See the section BATCH OUTPUT below for details.
--batch-all-objectsInstead of reading a list of objects on stdin, perform the requested batch operation on all objects in the repository and any alternate object stores (not just reachable objects). Requires --batch or --batch-check be specified. Note that the objects are visited in order sorted by their hashes.
--bufferNormally batch output is flushed after each object is output, so that a process can interactively read and write from cat-file. With this option, the output uses normal stdio buffering; this is much more efficient when invoking --batch-check on a large number of objects.
--unorderedWhen --batch-all-objects is in use, visit objects in an order which may be more efficient for accessing the object contents than hash order. The exact details of the order are unspecified, but if you do not require a specific order, this should generally result in faster output, especially with --batch. Note that cat-file will still show each object only once, even if it is stored multiple times in the repository.
--allow-unknown-typeAllow -s or -t to query broken/corrupt objects of unknown type.
--follow-symlinksWith --batch or --batch-check, follow symlinks inside the repository when requesting objects with extended SHA-1 expressions of the form tree-ish:path-in-tree. Instead of providing output about the link itself, provide output about the linked-to object. If a symlink points outside the tree-ish (e.g. a link to /foo or a root-level link to ../foo), the portion of the link which is outside the tree will be printed. This option does not (currently) work correctly when an object in the index is specified (e.g. :link instead of HEAD:link) rather than one in the tree. This option cannot (currently) be used unless --batch or --batch-check is used.

説明

リポジトリオブジェクトの内容や種類、サイズ情報を提供するコマンド。

関連

参考リンク

その他メモ

なし。