Raw
1 git-cat-file(1)
2 ===============
3
4 NAME
5 ----
6 git-cat-file - Provide contents or details of repository objects
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git cat-file' <type> <object>
12 'git cat-file' (-e | -p | -t | -s) <object>
13 'git cat-file' (--textconv | --filters)
14 [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
15 'git cat-file' (--batch | --batch-check | --batch-command) [--batch-all-objects]
16 [--buffer] [--follow-symlinks] [--unordered]
17 [--textconv | --filters] [-Z]
18
19 DESCRIPTION
20 -----------
21 Output the contents or other properties such as size, type or delta
22 information of one or more objects.
23
24 This command can operate in two modes, depending on whether an option
25 from the `--batch` family is specified.
26
27 In non-batch mode, the command provides information on an object
28 named on the command line.
29
30 In batch mode, arguments are read from standard input.
31
32 OPTIONS
33 -------
34 <object>::
35 The name of the object to show.
36 For a more complete list of ways to spell object names, see
37 the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
38
39 -t::
40 Instead of the content, show the object type identified by
41 `<object>`.
42
43 -s::
44 Instead of the content, show the object size identified by
45 `<object>`. If used with `--use-mailmap` option, will show
46 the size of updated object after replacing idents using the
47 mailmap mechanism.
48
49 -e::
50 Exit with zero status if `<object>` exists and is a valid
51 object. If `<object>` is of an invalid format, exit with non-zero
52 status and emit an error on stderr.
53
54 -p::
55 Pretty-print the contents of `<object>` based on its type.
56
57 <type>::
58 Typically this matches the real type of `<object>` but asking
59 for a type that can trivially be dereferenced from the given
60 `<object>` is also permitted. An example is to ask for a
61 "tree" with `<object>` being a commit object that contains it,
62 or to ask for a "blob" with `<object>` being a tag object that
63 points at it.
64
65 --mailmap::
66 --no-mailmap::
67 --use-mailmap::
68 --no-use-mailmap::
69 Use mailmap file to map author, committer and tagger names
70 and email addresses to canonical real names and email addresses.
71 See linkgit:git-shortlog[1].
72
73 --textconv::
74 Show the content as transformed by a textconv filter. In this case,
75 `<object>` has to be of the form `<tree-ish>:<path>`, or `:<path>` in
76 order to apply the filter to the content recorded in the index at
77 `<path>`.
78
79 --filters::
80 Show the content as converted by the filters configured in
81 the current working tree for the given `<path>` (i.e. smudge filters,
82 end-of-line conversion, etc). In this case, `<object>` has to be of
83 the form `<tree-ish>:<path>`, or `:<path>`.
84
85 --filter=<filter-spec>::
86 --no-filter::
87 Omit objects from the list of printed objects. This can only be used in
88 combination with one of the batched modes. Excluded objects that have
89 been explicitly requested via any of the batch modes that read objects
90 via standard input (`--batch`, `--batch-check`) will be reported as
91 "filtered". Excluded objects in `--batch-all-objects` mode will not be
92 printed at all. The '<filter-spec>' may be one of the following:
93 +
94 The form '--filter=blob:none' omits all blobs.
95 +
96 The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n
97 bytes or units. n may be zero. The suffixes k, m, and g can be used to name
98 units in KiB, MiB, or GiB. For example, 'blob:limit=1k' is the same as
99 'blob:limit=1024'.
100 +
101 The form '--filter=object:type=(tag|commit|tree|blob)' omits all objects which
102 are not of the requested type.
103
104 --path=<path>::
105 For use with `--textconv` or `--filters`, to allow specifying an object
106 name and a path separately, e.g. when it is difficult to figure out
107 the revision from which the blob came.
108
109 --batch::
110 --batch=<format>::
111 Print object information and contents for each object provided
112 on stdin. May not be combined with any other options or arguments
113 except `--textconv`, `--filters`, or `--use-mailmap`.
114 +
115 --
116 * When used with `--textconv` or `--filters`, the input lines
117 must specify the path, separated by whitespace. See the section
118 `BATCH OUTPUT` below for details.
119
120 * When used with `--use-mailmap`, for commit and tag objects, the
121 contents part of the output shows the identities replaced using the
122 mailmap mechanism, while the information part of the output shows
123 the size of the object as if it actually recorded the replacement
124 identities.
125 --
126
127 --batch-check::
128 --batch-check=<format>::
129 Print object information for each object provided on stdin. May not be
130 combined with any other options or arguments except `--textconv`, `--filters`
131 or `--use-mailmap`.
132 +
133 --
134 * When used with `--textconv` or `--filters`, the input lines must
135 specify the path, separated by whitespace. See the section
136 `BATCH OUTPUT` below for details.
137
138 * When used with `--use-mailmap`, for commit and tag objects, the
139 printed object information shows the size of the object as if the
140 identities recorded in it were replaced by the mailmap mechanism.
141 --
142
143 --batch-command::
144 --batch-command=<format>::
145 Enter a command mode that reads commands and arguments from stdin. May
146 only be combined with `--buffer`, `--textconv`, `--use-mailmap` or
147 `--filters`.
148 +
149 --
150 * When used with `--textconv` or `--filters`, the input lines must
151 specify the path, separated by whitespace. See the section
152 `BATCH OUTPUT` below for details.
153
154 * When used with `--use-mailmap`, for commit and tag objects, the
155 `contents` command shows the identities replaced using the
156 mailmap mechanism, while the `info` command shows the size
157 of the object as if it actually recorded the replacement
158 identities.
159 --
160 +
161 `--batch-command` recognizes the following commands:
162 +
163 --
164 contents <object>::
165 Print object contents for object reference `<object>`. This corresponds to
166 the output of `--batch`.
167
168 info <object>::
169 Print object info for object reference `<object>`. This corresponds to the
170 output of `--batch-check`.
171
172 flush::
173 Used with `--buffer` to execute all preceding commands that were issued
174 since the beginning or since the last flush was issued. When `--buffer`
175 is used, no output will come until a `flush` is issued. When `--buffer`
176 is not used, commands are flushed each time without issuing `flush`.
177
178 `mailmap (<bool>)`::
179 Enable or disable mailmap for subsequent commands. The `<bool>`
180 argument accepts the same boolean values as linkgit:git-config[1].
181 The mailmap data is read upon the first use and only once.
182 --
183 +
184
185 --batch-all-objects::
186 Instead of reading a list of objects on stdin, perform the
187 requested batch operation on all objects in the repository and
188 any alternate object stores (not just reachable objects).
189 Requires `--batch` or `--batch-check` be specified. By default,
190 the objects are visited in order sorted by their hashes; see
191 also `--unordered` below. Objects are presented as-is, without
192 respecting the "replace" mechanism of linkgit:git-replace[1].
193
194 --buffer::
195 Normally batch output is flushed after each object is output, so
196 that a process can interactively read and write from
197 `cat-file`. With this option, the output uses normal stdio
198 buffering; this is much more efficient when invoking
199 `--batch-check` or `--batch-command` on a large number of objects.
200
201 --unordered::
202 When `--batch-all-objects` is in use, visit objects in an
203 order which may be more efficient for accessing the object
204 contents than hash order. The exact details of the order are
205 unspecified, but if you do not require a specific order, this
206 should generally result in faster output, especially with
207 `--batch`. Note that `cat-file` will still show each object
208 only once, even if it is stored multiple times in the
209 repository.
210
211 --follow-symlinks::
212 With `--batch` or `--batch-check`, follow symlinks inside the
213 repository when requesting objects with extended SHA-1
214 expressions of the form tree-ish:path-in-tree. Instead of
215 providing output about the link itself, provide output about
216 the linked-to object. If a symlink points outside the
217 tree-ish (e.g. a link to `/foo` or a root-level link to `../foo`),
218 the portion of the link which is outside the tree will be
219 printed.
220 +
221 This option does not (currently) work correctly when an object in the
222 index is specified (e.g. `:link` instead of `HEAD:link`) rather than
223 one in the tree.
224 +
225 This option cannot (currently) be used unless `--batch` or
226 `--batch-check` is used.
227 +
228 For example, consider a git repository containing:
229 +
230 --
231 f: a file containing "hello\n"
232 link: a symlink to f
233 dir/link: a symlink to ../f
234 plink: a symlink to ../f
235 alink: a symlink to /etc/passwd
236 --
237 +
238 For a regular file `f`, `echo HEAD:f | git cat-file --batch` would print
239 +
240 --
241 ce013625030ba8dba906f756967f9e9ca394464a blob 6
242 --
243 +
244 And `echo HEAD:link | git cat-file --batch --follow-symlinks` would
245 print the same thing, as would `HEAD:dir/link`, as they both point at
246 `HEAD:f`.
247 +
248 Without `--follow-symlinks`, these would print data about the symlink
249 itself. In the case of `HEAD:link`, you would see
250 +
251 --
252 4d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
253 --
254 +
255 Both `plink` and `alink` point outside the tree, so they would
256 respectively print:
257 +
258 --
259 symlink 4
260 ../f
261
262 symlink 11
263 /etc/passwd
264 --
265
266 -Z::
267 Only meaningful with `--batch`, `--batch-check`, or
268 `--batch-command`; input and output is NUL-delimited instead of
269 newline-delimited.
270
271 -z::
272 Only meaningful with `--batch`, `--batch-check`, or
273 `--batch-command`; input is NUL-delimited instead of
274 newline-delimited. This option is deprecated in favor of
275 `-Z` as the output can otherwise be ambiguous.
276
277
278 OUTPUT
279 ------
280 If `-t` is specified, one of the `<type>`.
281
282 If `-s` is specified, the size of the `<object>` in bytes.
283
284 If `-e` is specified, no output, unless the `<object>` is malformed.
285
286 If `-p` is specified, the contents of `<object>` are pretty-printed.
287
288 If `<type>` is specified, the raw (though uncompressed) contents of the `<object>`
289 will be returned.
290
291 BATCH OUTPUT
292 ------------
293
294 If `--batch` or `--batch-check` is given, `cat-file` will read objects
295 from stdin, one per line, and print information about them in the same
296 order as they have been read. By default, the whole line is
297 considered as an object, as if it were fed to linkgit:git-rev-parse[1].
298
299 When `--batch-command` is given, `cat-file` will read commands from stdin,
300 one per line, and print information based on the command given. With
301 `--batch-command`, the `info` command followed by an object will print
302 information about the object the same way `--batch-check` would, and the
303 `contents` command followed by an object prints contents in the same way
304 `--batch` would.
305
306 You can specify the information shown for each object by using a custom
307 `<format>`. The `<format>` is copied literally to stdout for each
308 object, with placeholders of the form `%(atom)` expanded, followed by a
309 newline. The available atoms are:
310
311 `objectname`::
312 The full hex representation of the object name.
313
314 `objecttype`::
315 The type of the object (the same as `cat-file -t` reports).
316
317 `objectmode`::
318 If the specified object has mode information (such as a tree or
319 index entry), the mode expressed as an octal integer. Otherwise,
320 empty string.
321
322 `objectsize`::
323 The size, in bytes, of the object (the same as `cat-file -s`
324 reports).
325
326 `objectsize:disk`::
327 The size, in bytes, that the object takes up on disk. See the
328 note about on-disk sizes in the `CAVEATS` section below.
329
330 `deltabase`::
331 If the object is stored as a delta on-disk, this expands to the
332 full hex representation of the delta base object name.
333 Otherwise, expands to the null OID (all zeroes). See `CAVEATS`
334 below.
335
336 `rest`::
337 If this atom is used in the output string, input lines are split
338 at the first whitespace boundary. All characters before that
339 whitespace are considered to be the object name; characters
340 after that first run of whitespace (i.e., the "rest" of the
341 line) are output in place of the `%(rest)` atom.
342
343 If no format is specified, the default format is `%(objectname)
344 %(objecttype) %(objectsize)`.
345
346 If `--batch` is specified, or if `--batch-command` is used with the `contents`
347 command, the object information is followed by the object contents (consisting
348 of `%(objectsize)` bytes), followed by a newline.
349
350 For example, `--batch` without a custom format would produce:
351
352 -----------
353 <oid> SP <type> SP <size> LF
354 <contents> LF
355 -----------
356
357 Whereas `--batch-check='%(objectname) %(objecttype)'` would produce:
358
359 ------------
360 <oid> SP <type> LF
361 ------------
362
363 If a name is specified on stdin that cannot be resolved to an object in
364 the repository, then `cat-file` will ignore any custom format and print:
365
366 ------------
367 <object> SP missing LF
368 ------------
369
370 If a name is specified on stdin that is filtered out via `--filter=`,
371 then `cat-file` will ignore any custom format and print:
372
373 ------------
374 <object> SP excluded LF
375 ------------
376
377 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:
378
379 ------------
380 <object> SP ambiguous LF
381 ------------
382
383 If a name is specified that refers to a submodule entry in a tree and the
384 target object does not exist in the repository, then `cat-file` will ignore
385 any custom format and print (with the object ID of the submodule):
386
387 ------------
388 <oid> SP submodule LF
389 ------------
390
391 If `--follow-symlinks` is used, and a symlink in the repository points
392 outside the repository, then `cat-file` will ignore any custom format
393 and print:
394
395 ------------
396 symlink SP <size> LF
397 <symlink> LF
398 ------------
399
400 The symlink will either be absolute (beginning with a `/`), or relative
401 to the tree root. For instance, if dir/link points to `../../foo`, then
402 `<symlink>` will be `../foo`. `<size>` is the size of the symlink in bytes.
403
404 If `--follow-symlinks` is used, the following error messages will be
405 displayed:
406
407 ------------
408 <object> SP missing LF
409 ------------
410 is printed when the initial symlink requested does not exist.
411
412 ------------
413 dangling SP <size> LF
414 <object> LF
415 ------------
416 is printed when the initial symlink exists, but something that
417 it (transitive-of) points to does not.
418
419 ------------
420 loop SP <size> LF
421 <object> LF
422 ------------
423 is printed for symlink loops (or any symlinks that
424 require more than 40 link resolutions to resolve).
425
426 ------------
427 notdir SP <size> LF
428 <object> LF
429 ------------
430 is printed when, during symlink resolution, a file is used as a
431 directory name.
432
433 Alternatively, when `-Z` is passed, the line feeds in any of the above examples
434 are replaced with NUL terminators. This ensures that output will be parsable if
435 the output itself would contain a linefeed and is thus recommended for
436 scripting purposes.
437
438 CAVEATS
439 -------
440
441 Note that the sizes of objects on disk are reported accurately, but care
442 should be taken in drawing conclusions about which refs or objects are
443 responsible for disk usage. The size of a packed non-delta object may be
444 much larger than the size of objects which delta against it, but the
445 choice of which object is the base and which is the delta is arbitrary
446 and is subject to change during a repack.
447
448 Note also that multiple copies of an object may be present in the object
449 database; in this case, it is undefined which copy's size or delta base
450 will be reported.
451
452 GIT
453 ---
454 Part of the linkgit:git[1] suite