]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-cat-file.txt
Merge branch 'rs/rebase-use-strvec-pushf'
[thirdparty/git.git] / Documentation / git-cat-file.txt
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) <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]
19
20 DESCRIPTION
21 -----------
22 Output the contents or other properties such as size, type or delta
23 information of one or more objects.
24
25 This command can operate in two modes, depending on whether an option
26 from the `--batch` family is specified.
27
28 In non-batch mode, the command provides information on an object
29 named on the command line.
30
31 In batch mode, arguments are read from standard input.
32
33 OPTIONS
34 -------
35 <object>::
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].
39
40 -t::
41 Instead of the content, show the object type identified by
42 `<object>`.
43
44 -s::
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
48 mailmap mechanism.
49
50 -e::
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.
54
55 -p::
56 Pretty-print the contents of `<object>` based on its type.
57
58 <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
64 points at it.
65
66 --[no-]mailmap::
67 --[no-]use-mailmap::
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].
71
72 --textconv::
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
76 `<path>`.
77
78 --filters::
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>`.
83
84 --path=<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.
88
89 --batch::
90 --batch=<format>::
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`.
94 +
95 --
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.
99
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
104 identities.
105 --
106
107 --batch-check::
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`
111 or `--use-mailmap`.
112 +
113 --
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.
117
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.
121 --
122
123 --batch-command::
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
127 `--filters`.
128 +
129 --
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.
133
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
138 identities.
139 --
140 +
141 `--batch-command` recognizes the following commands:
142 +
143 --
144 contents <object>::
145 Print object contents for object reference `<object>`. This corresponds to
146 the output of `--batch`.
147
148 info <object>::
149 Print object info for object reference `<object>`. This corresponds to the
150 output of `--batch-check`.
151
152 flush::
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`.
157 --
158 +
159
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].
168
169 --buffer::
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.
175
176 --unordered::
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
184 repository.
185
186 --allow-unknown-type::
187 Allow `-s` or `-t` to query broken/corrupt objects of unknown type.
188
189 --follow-symlinks::
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
197 printed.
198 +
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
201 one in the tree.
202 +
203 This option cannot (currently) be used unless `--batch` or
204 `--batch-check` is used.
205 +
206 For example, consider a git repository containing:
207 +
208 --
209 f: a file containing "hello\n"
210 link: a symlink to f
211 dir/link: a symlink to ../f
212 plink: a symlink to ../f
213 alink: a symlink to /etc/passwd
214 --
215 +
216 For a regular file `f`, `echo HEAD:f | git cat-file --batch` would print
217 +
218 --
219 ce013625030ba8dba906f756967f9e9ca394464a blob 6
220 --
221 +
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
224 `HEAD:f`.
225 +
226 Without `--follow-symlinks`, these would print data about the symlink
227 itself. In the case of `HEAD:link`, you would see
228 +
229 --
230 4d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
231 --
232 +
233 Both `plink` and `alink` point outside the tree, so they would
234 respectively print:
235 +
236 --
237 symlink 4
238 ../f
239
240 symlink 11
241 /etc/passwd
242 --
243
244 -Z::
245 Only meaningful with `--batch`, `--batch-check`, or
246 `--batch-command`; input and output is NUL-delimited instead of
247 newline-delimited.
248
249 -z::
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.
254
255
256 OUTPUT
257 ------
258 If `-t` is specified, one of the `<type>`.
259
260 If `-s` is specified, the size of the `<object>` in bytes.
261
262 If `-e` is specified, no output, unless the `<object>` is malformed.
263
264 If `-p` is specified, the contents of `<object>` are pretty-printed.
265
266 If `<type>` is specified, the raw (though uncompressed) contents of the `<object>`
267 will be returned.
268
269 BATCH OUTPUT
270 ------------
271
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].
276
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
282 `--batch` would.
283
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:
288
289 `objectname`::
290 The full hex representation of the object name.
291
292 `objecttype`::
293 The type of the object (the same as `cat-file -t` reports).
294
295 `objectsize`::
296 The size, in bytes, of the object (the same as `cat-file -s`
297 reports).
298
299 `objectsize:disk`::
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.
302
303 `deltabase`::
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`
307 below.
308
309 `rest`::
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.
315
316 If no format is specified, the default format is `%(objectname)
317 %(objecttype) %(objectsize)`.
318
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.
322
323 For example, `--batch` without a custom format would produce:
324
325 ------------
326 <oid> SP <type> SP <size> LF
327 <contents> LF
328 ------------
329
330 Whereas `--batch-check='%(objectname) %(objecttype)'` would produce:
331
332 ------------
333 <oid> SP <type> LF
334 ------------
335
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:
338
339 ------------
340 <object> SP missing LF
341 ------------
342
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:
344
345 ------------
346 <object> SP ambiguous LF
347 ------------
348
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
351 and print:
352
353 ------------
354 symlink SP <size> LF
355 <symlink> LF
356 ------------
357
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.
361
362 If `--follow-symlinks` is used, the following error messages will be
363 displayed:
364
365 ------------
366 <object> SP missing LF
367 ------------
368 is printed when the initial symlink requested does not exist.
369
370 ------------
371 dangling SP <size> LF
372 <object> LF
373 ------------
374 is printed when the initial symlink exists, but something that
375 it (transitive-of) points to does not.
376
377 ------------
378 loop SP <size> LF
379 <object> LF
380 ------------
381 is printed for symlink loops (or any symlinks that
382 require more than 40 link resolutions to resolve).
383
384 ------------
385 notdir SP <size> LF
386 <object> LF
387 ------------
388 is printed when, during symlink resolution, a file is used as a
389 directory name.
390
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
394 scripting purposes.
395
396 CAVEATS
397 -------
398
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.
405
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
408 will be reported.
409
410 GIT
411 ---
412 Part of the linkgit:git[1] suite