6 git-cat-file - Provide contents or details of repository objects
11 'git cat-file' <type> <object>
12 'git cat-file' (-e | -p) <object>
13 'git cat-file' (-t | -s) [--allow-unknown-type] <object>
14 'git cat-file' (--textconv | --filters)
15 [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
16 'git cat-file' (--batch | --batch-check | --batch-command) [--batch-all-objects]
17 [--buffer] [--follow-symlinks] [--unordered]
18 [--textconv | --filters] [-Z]
22 Output the contents or other properties such as size, type or delta
23 information of one or more objects.
25 This command can operate in two modes, depending on whether an option
26 from the `--batch` family is specified.
28 In non-batch mode, the command provides information on an object
29 named on the command line.
31 In batch mode, arguments are read from standard input.
36 The name of the object to show.
37 For a more complete list of ways to spell object names, see
38 the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
41 Instead of the content, show the object type identified by
45 Instead of the content, show the object size identified by
46 `<object>`. If used with `--use-mailmap` option, will show
47 the size of updated object after replacing idents using the
51 Exit with zero status if `<object>` exists and is a valid
52 object. If `<object>` is of an invalid format, exit with non-zero
53 status and emit an error on stderr.
56 Pretty-print the contents of `<object>` based on its type.
59 Typically this matches the real type of `<object>` but asking
60 for a type that can trivially be dereferenced from the given
61 `<object>` is also permitted. An example is to ask for a
62 "tree" with `<object>` being a commit object that contains it,
63 or to ask for a "blob" with `<object>` being a tag object that
68 Use mailmap file to map author, committer and tagger names
69 and email addresses to canonical real names and email addresses.
70 See linkgit:git-shortlog[1].
73 Show the content as transformed by a textconv filter. In this case,
74 `<object>` has to be of the form `<tree-ish>:<path>`, or `:<path>` in
75 order to apply the filter to the content recorded in the index at
79 Show the content as converted by the filters configured in
80 the current working tree for the given `<path>` (i.e. smudge filters,
81 end-of-line conversion, etc). In this case, `<object>` has to be of
82 the form `<tree-ish>:<path>`, or `:<path>`.
85 For use with `--textconv` or `--filters`, to allow specifying an object
86 name and a path separately, e.g. when it is difficult to figure out
87 the revision from which the blob came.
91 Print object information and contents for each object provided
92 on stdin. May not be combined with any other options or arguments
93 except `--textconv`, `--filters`, or `--use-mailmap`.
96 * When used with `--textconv` or `--filters`, the input lines
97 must specify the path, separated by whitespace. See the section
98 `BATCH OUTPUT` below for details.
100 * When used with `--use-mailmap`, for commit and tag objects, the
101 contents part of the output shows the identities replaced using the
102 mailmap mechanism, while the information part of the output shows
103 the size of the object as if it actually recorded the replacement
108 --batch-check=<format>::
109 Print object information for each object provided on stdin. May not be
110 combined with any other options or arguments except `--textconv`, `--filters`
114 * When used with `--textconv` or `--filters`, the input lines must
115 specify the path, separated by whitespace. See the section
116 `BATCH OUTPUT` below for details.
118 * When used with `--use-mailmap`, for commit and tag objects, the
119 printed object information shows the size of the object as if the
120 identities recorded in it were replaced by the mailmap mechanism.
124 --batch-command=<format>::
125 Enter a command mode that reads commands and arguments from stdin. May
126 only be combined with `--buffer`, `--textconv`, `--use-mailmap` or
130 * When used with `--textconv` or `--filters`, the input lines must
131 specify the path, separated by whitespace. See the section
132 `BATCH OUTPUT` below for details.
134 * When used with `--use-mailmap`, for commit and tag objects, the
135 `contents` command shows the identities replaced using the
136 mailmap mechanism, while the `info` command shows the size
137 of the object as if it actually recorded the replacement
141 `--batch-command` recognizes the following commands:
145 Print object contents for object reference `<object>`. This corresponds to
146 the output of `--batch`.
149 Print object info for object reference `<object>`. This corresponds to the
150 output of `--batch-check`.
153 Used with `--buffer` to execute all preceding commands that were issued
154 since the beginning or since the last flush was issued. When `--buffer`
155 is used, no output will come until a `flush` is issued. When `--buffer`
156 is not used, commands are flushed each time without issuing `flush`.
160 --batch-all-objects::
161 Instead of reading a list of objects on stdin, perform the
162 requested batch operation on all objects in the repository and
163 any alternate object stores (not just reachable objects).
164 Requires `--batch` or `--batch-check` be specified. By default,
165 the objects are visited in order sorted by their hashes; see
166 also `--unordered` below. Objects are presented as-is, without
167 respecting the "replace" mechanism of linkgit:git-replace[1].
170 Normally batch output is flushed after each object is output, so
171 that a process can interactively read and write from
172 `cat-file`. With this option, the output uses normal stdio
173 buffering; this is much more efficient when invoking
174 `--batch-check` or `--batch-command` on a large number of objects.
177 When `--batch-all-objects` is in use, visit objects in an
178 order which may be more efficient for accessing the object
179 contents than hash order. The exact details of the order are
180 unspecified, but if you do not require a specific order, this
181 should generally result in faster output, especially with
182 `--batch`. Note that `cat-file` will still show each object
183 only once, even if it is stored multiple times in the
186 --allow-unknown-type::
187 Allow `-s` or `-t` to query broken/corrupt objects of unknown type.
190 With `--batch` or `--batch-check`, follow symlinks inside the
191 repository when requesting objects with extended SHA-1
192 expressions of the form tree-ish:path-in-tree. Instead of
193 providing output about the link itself, provide output about
194 the linked-to object. If a symlink points outside the
195 tree-ish (e.g. a link to `/foo` or a root-level link to `../foo`),
196 the portion of the link which is outside the tree will be
199 This option does not (currently) work correctly when an object in the
200 index is specified (e.g. `:link` instead of `HEAD:link`) rather than
203 This option cannot (currently) be used unless `--batch` or
204 `--batch-check` is used.
206 For example, consider a git repository containing:
209 f: a file containing "hello\n"
211 dir/link: a symlink to ../f
212 plink: a symlink to ../f
213 alink: a symlink to /etc/passwd
216 For a regular file `f`, `echo HEAD:f | git cat-file --batch` would print
219 ce013625030ba8dba906f756967f9e9ca394464a blob 6
222 And `echo HEAD:link | git cat-file --batch --follow-symlinks` would
223 print the same thing, as would `HEAD:dir/link`, as they both point at
226 Without `--follow-symlinks`, these would print data about the symlink
227 itself. In the case of `HEAD:link`, you would see
230 4d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
233 Both `plink` and `alink` point outside the tree, so they would
245 Only meaningful with `--batch`, `--batch-check`, or
246 `--batch-command`; input and output is NUL-delimited instead of
250 Only meaningful with `--batch`, `--batch-check`, or
251 `--batch-command`; input is NUL-delimited instead of
252 newline-delimited. This option is deprecated in favor of
253 `-Z` as the output can otherwise be ambiguous.
258 If `-t` is specified, one of the `<type>`.
260 If `-s` is specified, the size of the `<object>` in bytes.
262 If `-e` is specified, no output, unless the `<object>` is malformed.
264 If `-p` is specified, the contents of `<object>` are pretty-printed.
266 If `<type>` is specified, the raw (though uncompressed) contents of the `<object>`
272 If `--batch` or `--batch-check` is given, `cat-file` will read objects
273 from stdin, one per line, and print information about them. By default,
274 the whole line is considered as an object, as if it were fed to
275 linkgit:git-rev-parse[1].
277 When `--batch-command` is given, `cat-file` will read commands from stdin,
278 one per line, and print information based on the command given. With
279 `--batch-command`, the `info` command followed by an object will print
280 information about the object the same way `--batch-check` would, and the
281 `contents` command followed by an object prints contents in the same way
284 You can specify the information shown for each object by using a custom
285 `<format>`. The `<format>` is copied literally to stdout for each
286 object, with placeholders of the form `%(atom)` expanded, followed by a
287 newline. The available atoms are:
290 The full hex representation of the object name.
293 The type of the object (the same as `cat-file -t` reports).
296 The size, in bytes, of the object (the same as `cat-file -s`
300 The size, in bytes, that the object takes up on disk. See the
301 note about on-disk sizes in the `CAVEATS` section below.
304 If the object is stored as a delta on-disk, this expands to the
305 full hex representation of the delta base object name.
306 Otherwise, expands to the null OID (all zeroes). See `CAVEATS`
310 If this atom is used in the output string, input lines are split
311 at the first whitespace boundary. All characters before that
312 whitespace are considered to be the object name; characters
313 after that first run of whitespace (i.e., the "rest" of the
314 line) are output in place of the `%(rest)` atom.
316 If no format is specified, the default format is `%(objectname)
317 %(objecttype) %(objectsize)`.
319 If `--batch` is specified, or if `--batch-command` is used with the `contents`
320 command, the object information is followed by the object contents (consisting
321 of `%(objectsize)` bytes), followed by a newline.
323 For example, `--batch` without a custom format would produce:
326 <oid> SP <type> SP <size> LF
330 Whereas `--batch-check='%(objectname) %(objecttype)'` would produce:
336 If a name is specified on stdin that cannot be resolved to an object in
337 the repository, then `cat-file` will ignore any custom format and print:
340 <object> SP missing LF
343 If a name is specified that might refer to more than one object (an ambiguous short sha), then `cat-file` will ignore any custom format and print:
346 <object> SP ambiguous LF
349 If `--follow-symlinks` is used, and a symlink in the repository points
350 outside the repository, then `cat-file` will ignore any custom format
358 The symlink will either be absolute (beginning with a `/`), or relative
359 to the tree root. For instance, if dir/link points to `../../foo`, then
360 `<symlink>` will be `../foo`. `<size>` is the size of the symlink in bytes.
362 If `--follow-symlinks` is used, the following error messages will be
366 <object> SP missing LF
368 is printed when the initial symlink requested does not exist.
371 dangling SP <size> LF
374 is printed when the initial symlink exists, but something that
375 it (transitive-of) points to does not.
381 is printed for symlink loops (or any symlinks that
382 require more than 40 link resolutions to resolve).
388 is printed when, during symlink resolution, a file is used as a
391 Alternatively, when `-Z` is passed, the line feeds in any of the above examples
392 are replaced with NUL terminators. This ensures that output will be parsable if
393 the output itself would contain a linefeed and is thus recommended for
399 Note that the sizes of objects on disk are reported accurately, but care
400 should be taken in drawing conclusions about which refs or objects are
401 responsible for disk usage. The size of a packed non-delta object may be
402 much larger than the size of objects which delta against it, but the
403 choice of which object is the base and which is the delta is arbitrary
404 and is subject to change during a repack.
406 Note also that multiple copies of an object may be present in the object
407 database; in this case, it is undefined which copy's size or delta base
412 Part of the linkgit:git[1] suite