Git fork
1git-cat-file(1)
2===============
3
4NAME
5----
6git-cat-file - Provide contents or details of repository objects
7
8SYNOPSIS
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
19DESCRIPTION
20-----------
21Output the contents or other properties such as size, type or delta
22information of one or more objects.
23
24This command can operate in two modes, depending on whether an option
25from the `--batch` family is specified.
26
27In non-batch mode, the command provides information on an object
28named on the command line.
29
30In batch mode, arguments are read from standard input.
31
32OPTIONS
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+
94The form '--filter=blob:none' omits all blobs.
95+
96The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n
97bytes or units. n may be zero. The suffixes k, m, and g can be used to name
98units in KiB, MiB, or GiB. For example, 'blob:limit=1k' is the same as
99'blob:limit=1024'.
100+
101The form '--filter=object:type=(tag|commit|tree|blob)' omits all objects which
102are 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--
164contents <object>::
165 Print object contents for object reference `<object>`. This corresponds to
166 the output of `--batch`.
167
168info <object>::
169 Print object info for object reference `<object>`. This corresponds to the
170 output of `--batch-check`.
171
172flush::
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+
179
180--batch-all-objects::
181 Instead of reading a list of objects on stdin, perform the
182 requested batch operation on all objects in the repository and
183 any alternate object stores (not just reachable objects).
184 Requires `--batch` or `--batch-check` be specified. By default,
185 the objects are visited in order sorted by their hashes; see
186 also `--unordered` below. Objects are presented as-is, without
187 respecting the "replace" mechanism of linkgit:git-replace[1].
188
189--buffer::
190 Normally batch output is flushed after each object is output, so
191 that a process can interactively read and write from
192 `cat-file`. With this option, the output uses normal stdio
193 buffering; this is much more efficient when invoking
194 `--batch-check` or `--batch-command` on a large number of objects.
195
196--unordered::
197 When `--batch-all-objects` is in use, visit objects in an
198 order which may be more efficient for accessing the object
199 contents than hash order. The exact details of the order are
200 unspecified, but if you do not require a specific order, this
201 should generally result in faster output, especially with
202 `--batch`. Note that `cat-file` will still show each object
203 only once, even if it is stored multiple times in the
204 repository.
205
206--follow-symlinks::
207 With `--batch` or `--batch-check`, follow symlinks inside the
208 repository when requesting objects with extended SHA-1
209 expressions of the form tree-ish:path-in-tree. Instead of
210 providing output about the link itself, provide output about
211 the linked-to object. If a symlink points outside the
212 tree-ish (e.g. a link to `/foo` or a root-level link to `../foo`),
213 the portion of the link which is outside the tree will be
214 printed.
215+
216This option does not (currently) work correctly when an object in the
217index is specified (e.g. `:link` instead of `HEAD:link`) rather than
218one in the tree.
219+
220This option cannot (currently) be used unless `--batch` or
221`--batch-check` is used.
222+
223For example, consider a git repository containing:
224+
225--
226 f: a file containing "hello\n"
227 link: a symlink to f
228 dir/link: a symlink to ../f
229 plink: a symlink to ../f
230 alink: a symlink to /etc/passwd
231--
232+
233For a regular file `f`, `echo HEAD:f | git cat-file --batch` would print
234+
235--
236 ce013625030ba8dba906f756967f9e9ca394464a blob 6
237--
238+
239And `echo HEAD:link | git cat-file --batch --follow-symlinks` would
240print the same thing, as would `HEAD:dir/link`, as they both point at
241`HEAD:f`.
242+
243Without `--follow-symlinks`, these would print data about the symlink
244itself. In the case of `HEAD:link`, you would see
245+
246--
247 4d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
248--
249+
250Both `plink` and `alink` point outside the tree, so they would
251respectively print:
252+
253--
254 symlink 4
255 ../f
256
257 symlink 11
258 /etc/passwd
259--
260
261-Z::
262 Only meaningful with `--batch`, `--batch-check`, or
263 `--batch-command`; input and output is NUL-delimited instead of
264 newline-delimited.
265
266-z::
267 Only meaningful with `--batch`, `--batch-check`, or
268 `--batch-command`; input is NUL-delimited instead of
269 newline-delimited. This option is deprecated in favor of
270 `-Z` as the output can otherwise be ambiguous.
271
272
273OUTPUT
274------
275If `-t` is specified, one of the `<type>`.
276
277If `-s` is specified, the size of the `<object>` in bytes.
278
279If `-e` is specified, no output, unless the `<object>` is malformed.
280
281If `-p` is specified, the contents of `<object>` are pretty-printed.
282
283If `<type>` is specified, the raw (though uncompressed) contents of the `<object>`
284will be returned.
285
286BATCH OUTPUT
287------------
288
289If `--batch` or `--batch-check` is given, `cat-file` will read objects
290from stdin, one per line, and print information about them in the same
291order as they have been read. By default, the whole line is
292considered as an object, as if it were fed to linkgit:git-rev-parse[1].
293
294When `--batch-command` is given, `cat-file` will read commands from stdin,
295one per line, and print information based on the command given. With
296`--batch-command`, the `info` command followed by an object will print
297information about the object the same way `--batch-check` would, and the
298`contents` command followed by an object prints contents in the same way
299`--batch` would.
300
301You can specify the information shown for each object by using a custom
302`<format>`. The `<format>` is copied literally to stdout for each
303object, with placeholders of the form `%(atom)` expanded, followed by a
304newline. The available atoms are:
305
306`objectname`::
307 The full hex representation of the object name.
308
309`objecttype`::
310 The type of the object (the same as `cat-file -t` reports).
311
312`objectmode`::
313 If the specified object has mode information (such as a tree or
314 index entry), the mode expressed as an octal integer. Otherwise,
315 empty string.
316
317`objectsize`::
318 The size, in bytes, of the object (the same as `cat-file -s`
319 reports).
320
321`objectsize:disk`::
322 The size, in bytes, that the object takes up on disk. See the
323 note about on-disk sizes in the `CAVEATS` section below.
324
325`deltabase`::
326 If the object is stored as a delta on-disk, this expands to the
327 full hex representation of the delta base object name.
328 Otherwise, expands to the null OID (all zeroes). See `CAVEATS`
329 below.
330
331`rest`::
332 If this atom is used in the output string, input lines are split
333 at the first whitespace boundary. All characters before that
334 whitespace are considered to be the object name; characters
335 after that first run of whitespace (i.e., the "rest" of the
336 line) are output in place of the `%(rest)` atom.
337
338If no format is specified, the default format is `%(objectname)
339%(objecttype) %(objectsize)`.
340
341If `--batch` is specified, or if `--batch-command` is used with the `contents`
342command, the object information is followed by the object contents (consisting
343of `%(objectsize)` bytes), followed by a newline.
344
345For example, `--batch` without a custom format would produce:
346
347-----------
348<oid> SP <type> SP <size> LF
349<contents> LF
350-----------
351
352Whereas `--batch-check='%(objectname) %(objecttype)'` would produce:
353
354------------
355<oid> SP <type> LF
356------------
357
358If a name is specified on stdin that cannot be resolved to an object in
359the repository, then `cat-file` will ignore any custom format and print:
360
361------------
362<object> SP missing LF
363------------
364
365If a name is specified on stdin that is filtered out via `--filter=`,
366then `cat-file` will ignore any custom format and print:
367
368------------
369<object> SP excluded LF
370------------
371
372If 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:
373
374------------
375<object> SP ambiguous LF
376------------
377
378If a name is specified that refers to a submodule entry in a tree and the
379target object does not exist in the repository, then `cat-file` will ignore
380any custom format and print (with the object ID of the submodule):
381
382------------
383<oid> SP submodule LF
384------------
385
386If `--follow-symlinks` is used, and a symlink in the repository points
387outside the repository, then `cat-file` will ignore any custom format
388and print:
389
390------------
391symlink SP <size> LF
392<symlink> LF
393------------
394
395The symlink will either be absolute (beginning with a `/`), or relative
396to the tree root. For instance, if dir/link points to `../../foo`, then
397`<symlink>` will be `../foo`. `<size>` is the size of the symlink in bytes.
398
399If `--follow-symlinks` is used, the following error messages will be
400displayed:
401
402------------
403<object> SP missing LF
404------------
405is printed when the initial symlink requested does not exist.
406
407------------
408dangling SP <size> LF
409<object> LF
410------------
411is printed when the initial symlink exists, but something that
412it (transitive-of) points to does not.
413
414------------
415loop SP <size> LF
416<object> LF
417------------
418is printed for symlink loops (or any symlinks that
419require more than 40 link resolutions to resolve).
420
421------------
422notdir SP <size> LF
423<object> LF
424------------
425is printed when, during symlink resolution, a file is used as a
426directory name.
427
428Alternatively, when `-Z` is passed, the line feeds in any of the above examples
429are replaced with NUL terminators. This ensures that output will be parsable if
430the output itself would contain a linefeed and is thus recommended for
431scripting purposes.
432
433CAVEATS
434-------
435
436Note that the sizes of objects on disk are reported accurately, but care
437should be taken in drawing conclusions about which refs or objects are
438responsible for disk usage. The size of a packed non-delta object may be
439much larger than the size of objects which delta against it, but the
440choice of which object is the base and which is the delta is arbitrary
441and is subject to change during a repack.
442
443Note also that multiple copies of an object may be present in the object
444database; in this case, it is undefined which copy's size or delta base
445will be reported.
446
447GIT
448---
449Part of the linkgit:git[1] suite