]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-cat-file.txt
Merge branch 'jk/fsck-indices-in-worktrees'
[thirdparty/git.git] / Documentation / git-cat-file.txt
CommitLineData
2cf565c5
DG
1git-cat-file(1)
2===============
2cf565c5
DG
3
4NAME
5----
d83a42f3 6git-cat-file - Provide content or type and size information for repository objects
2cf565c5
DG
7
8
9SYNOPSIS
10--------
cdf222f5 11[verse]
97fe7250
ÆAB
12'git cat-file' <type> <object>
13'git cat-file' (-e | -p) <object>
83dc4434 14'git cat-file' (-t | -s) [--allow-unknown-type] <object>
473fa2df 15'git cat-file' (--batch | --batch-check | --batch-command) [--batch-all-objects]
97fe7250 16 [--buffer] [--follow-symlinks] [--unordered]
db9d67f2 17 [--textconv | --filters] [-z]
83dc4434 18'git cat-file' (--textconv | --filters)
97fe7250 19 [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
2cf565c5
DG
20
21DESCRIPTION
22-----------
d83a42f3 23In its first form, the command provides the content or the type of an object in
23f8239b 24the repository. The type is required unless `-t` or `-p` is used to find the
b9e62f60
JS
25object type, or `-s` is used to find the object size, or `--textconv` or
26`--filters` is used (which imply type "blob").
05d5667f 27
d83a42f3 28In the second form, a list of objects (separated by linefeeds) is provided on
32145943
JS
29stdin, and the SHA-1, type, and size of each object is printed on stdout. The
30output format can be overridden using the optional `<format>` argument. If
31either `--textconv` or `--filters` was specified, the input is expected to
748aa1aa
PW
32list the object names followed by the path name, separated by a single
33whitespace, so that the appropriate drivers can be determined.
2cf565c5
DG
34
35OPTIONS
36-------
37<object>::
8933364d
AK
38 The name of the object to show.
39 For a more complete list of ways to spell object names, see
9d83e382 40 the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
2cf565c5
DG
41
42-t::
43 Instead of the content, show the object type identified by
4f0ba2d5 44 `<object>`.
2cf565c5 45
62bb9960
JH
46-s::
47 Instead of the content, show the object size identified by
49050a04
SA
48 `<object>`. If used with `--use-mailmap` option, will show
49 the size of updated object after replacing idents using the
50 mailmap mechanism.
62bb9960 51
7950571a 52-e::
4f0ba2d5
DL
53 Exit with zero status if `<object>` exists and is a valid
54 object. If `<object>` is of an invalid format exit with non-zero and
9bd2ce54 55 emits an error on stderr.
7950571a 56
ed90cbf5 57-p::
4f0ba2d5 58 Pretty-print the contents of `<object>` based on its type.
ed90cbf5 59
2cf565c5 60<type>::
4f0ba2d5 61 Typically this matches the real type of `<object>` but asking
f73ae1fc 62 for a type that can trivially be dereferenced from the given
4f0ba2d5
DL
63 `<object>` is also permitted. An example is to ask for a
64 "tree" with `<object>` being a commit object that contains it,
65 or to ask for a "blob" with `<object>` being a tag object that
2cf565c5
DG
66 points at it.
67
ec031da9
SA
68--[no-]mailmap::
69--[no-]use-mailmap::
70 Use mailmap file to map author, committer and tagger names
71 and email addresses to canonical real names and email addresses.
72 See linkgit:git-shortlog[1].
73
9f77fe02
MG
74--textconv::
75 Show the content as transformed by a textconv filter. In this case,
4f0ba2d5 76 `<object>` has to be of the form `<tree-ish>:<path>`, or `:<path>` in
16dcc299 77 order to apply the filter to the content recorded in the index at
4f0ba2d5 78 `<path>`.
9f77fe02 79
b9e62f60
JS
80--filters::
81 Show the content as converted by the filters configured in
4f0ba2d5
DL
82 the current working tree for the given `<path>` (i.e. smudge filters,
83 end-of-line conversion, etc). In this case, `<object>` has to be of
84 the form `<tree-ish>:<path>`, or `:<path>`.
b9e62f60 85
7bcf3414 86--path=<path>::
4f0ba2d5 87 For use with `--textconv` or `--filters`, to allow specifying an object
7bcf3414
JS
88 name and a path separately, e.g. when it is difficult to figure out
89 the revision from which the blob came.
90
a8128ed6 91--batch::
93d2a607
JK
92--batch=<format>::
93 Print object information and contents for each object provided
a797c0ea
SA
94 on stdin. May not be combined with any other options or arguments
95 except `--textconv`, `--filters`, or `--use-mailmap`.
8534bb4c
96+
97--
a797c0ea
SA
98 * When used with `--textconv` or `--filters`, the input lines
99 must specify the path, separated by whitespace. See the section
100 `BATCH OUTPUT` below for details.
8534bb4c 101
a797c0ea
SA
102 * When used with `--use-mailmap`, for commit and tag objects, the
103 contents part of the output shows the identities replaced using the
104 mailmap mechanism, while the information part of the output shows
105 the size of the object as if it actually recorded the replacement
106 identities.
8534bb4c 107--
a8128ed6 108
05d5667f 109--batch-check::
93d2a607 110--batch-check=<format>::
a797c0ea
SA
111 Print object information for each object provided on stdin. May not be
112 combined with any other options or arguments except `--textconv`, `--filters`
113 or `--use-mailmap`.
8534bb4c
114+
115--
a797c0ea
SA
116 * When used with `--textconv` or `--filters`, the input lines must
117 specify the path, separated by whitespace. See the section
118 `BATCH OUTPUT` below for details.
8534bb4c 119
a797c0ea
SA
120 * When used with `--use-mailmap`, for commit and tag objects, the
121 printed object information shows the size of the object as if the
122 identities recorded in it were replaced by the mailmap mechanism.
8534bb4c 123--
05d5667f 124
440c705e
JC
125--batch-command::
126--batch-command=<format>::
127 Enter a command mode that reads commands and arguments from stdin. May
a797c0ea
SA
128 only be combined with `--buffer`, `--textconv`, `--use-mailmap` or
129 `--filters`.
8534bb4c
130+
131--
a797c0ea
SA
132 * When used with `--textconv` or `--filters`, the input lines must
133 specify the path, separated by whitespace. See the section
134 `BATCH OUTPUT` below for details.
8534bb4c 135
a797c0ea
SA
136 * When used with `--use-mailmap`, for commit and tag objects, the
137 `contents` command shows the identities replaced using the
138 mailmap mechanism, while the `info` command shows the size
139 of the object as if it actually recorded the replacement
140 identities.
8534bb4c 141--
440c705e
JC
142+
143`--batch-command` recognizes the following commands:
144+
145--
146contents <object>::
147 Print object contents for object reference `<object>`. This corresponds to
148 the output of `--batch`.
149
150info <object>::
151 Print object info for object reference `<object>`. This corresponds to the
152 output of `--batch-check`.
153
154flush::
155 Used with `--buffer` to execute all preceding commands that were issued
156 since the beginning or since the last flush was issued. When `--buffer`
157 is used, no output will come until a `flush` is issued. When `--buffer`
158 is not used, commands are flushed each time without issuing `flush`.
159--
160+
161
6a951937
JK
162--batch-all-objects::
163 Instead of reading a list of objects on stdin, perform the
164 requested batch operation on all objects in the repository and
165 any alternate object stores (not just reachable objects).
c3660cfb
JK
166 Requires `--batch` or `--batch-check` be specified. By default,
167 the objects are visited in order sorted by their hashes; see
5c5b29b4
JK
168 also `--unordered` below. Objects are presented as-is, without
169 respecting the "replace" mechanism of linkgit:git-replace[1].
6a951937 170
fc4937c3
JK
171--buffer::
172 Normally batch output is flushed after each object is output, so
173 that a process can interactively read and write from
174 `cat-file`. With this option, the output uses normal stdio
175 buffering; this is much more efficient when invoking
440c705e 176 `--batch-check` or `--batch-command` on a large number of objects.
fc4937c3 177
0750bb5b
JK
178--unordered::
179 When `--batch-all-objects` is in use, visit objects in an
180 order which may be more efficient for accessing the object
181 contents than hash order. The exact details of the order are
182 unspecified, but if you do not require a specific order, this
183 should generally result in faster output, especially with
184 `--batch`. Note that `cat-file` will still show each object
185 only once, even if it is stored multiple times in the
186 repository.
187
39e4ae38 188--allow-unknown-type::
4f0ba2d5 189 Allow `-s` or `-t` to query broken/corrupt objects of unknown type.
39e4ae38 190
122d5346 191--follow-symlinks::
4f0ba2d5 192 With `--batch` or `--batch-check`, follow symlinks inside the
122d5346
DT
193 repository when requesting objects with extended SHA-1
194 expressions of the form tree-ish:path-in-tree. Instead of
195 providing output about the link itself, provide output about
196 the linked-to object. If a symlink points outside the
4f0ba2d5 197 tree-ish (e.g. a link to `/foo` or a root-level link to `../foo`),
122d5346
DT
198 the portion of the link which is outside the tree will be
199 printed.
200+
201This option does not (currently) work correctly when an object in the
202index is specified (e.g. `:link` instead of `HEAD:link`) rather than
203one in the tree.
204+
205This option cannot (currently) be used unless `--batch` or
206`--batch-check` is used.
207+
208For example, consider a git repository containing:
209+
210--
211 f: a file containing "hello\n"
212 link: a symlink to f
213 dir/link: a symlink to ../f
214 plink: a symlink to ../f
215 alink: a symlink to /etc/passwd
216--
217+
218For a regular file `f`, `echo HEAD:f | git cat-file --batch` would print
219+
220--
221 ce013625030ba8dba906f756967f9e9ca394464a blob 6
222--
223+
224And `echo HEAD:link | git cat-file --batch --follow-symlinks` would
225print the same thing, as would `HEAD:dir/link`, as they both point at
226`HEAD:f`.
227+
228Without `--follow-symlinks`, these would print data about the symlink
229itself. In the case of `HEAD:link`, you would see
230+
231--
232 4d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
233--
234+
235Both `plink` and `alink` point outside the tree, so they would
236respectively print:
237+
238--
239 symlink 4
240 ../f
241
242 symlink 11
243 /etc/passwd
244--
245
db9d67f2
TB
246-z::
247 Only meaningful with `--batch`, `--batch-check`, or
248 `--batch-command`; input is NUL-delimited instead of
249 newline-delimited.
250
122d5346 251
2cf565c5
DG
252OUTPUT
253------
4f0ba2d5 254If `-t` is specified, one of the `<type>`.
7950571a 255
4f0ba2d5 256If `-s` is specified, the size of the `<object>` in bytes.
7950571a 257
4f0ba2d5 258If `-e` is specified, no output, unless the `<object>` is malformed.
2cf565c5 259
4f0ba2d5 260If `-p` is specified, the contents of `<object>` are pretty-printed.
ed90cbf5 261
4f0ba2d5 262If `<type>` is specified, the raw (though uncompressed) contents of the `<object>`
05d5667f
AR
263will be returned.
264
93d2a607
JK
265BATCH OUTPUT
266------------
267
268If `--batch` or `--batch-check` is given, `cat-file` will read objects
97be0407
JK
269from stdin, one per line, and print information about them. By default,
270the whole line is considered as an object, as if it were fed to
271linkgit:git-rev-parse[1].
93d2a607 272
440c705e
JC
273When `--batch-command` is given, `cat-file` will read commands from stdin,
274one per line, and print information based on the command given. With
275`--batch-command`, the `info` command followed by an object will print
276information about the object the same way `--batch-check` would, and the
277`contents` command followed by an object prints contents in the same way
278`--batch` would.
279
93d2a607
JK
280You can specify the information shown for each object by using a custom
281`<format>`. The `<format>` is copied literally to stdout for each
282object, with placeholders of the form `%(atom)` expanded, followed by a
283newline. The available atoms are:
284
285`objectname`::
f4519607 286 The full hex representation of the object name.
93d2a607
JK
287
288`objecttype`::
be94568b 289 The type of the object (the same as `cat-file -t` reports).
93d2a607
JK
290
291`objectsize`::
292 The size, in bytes, of the object (the same as `cat-file -s`
293 reports).
294
a4ac1061
JK
295`objectsize:disk`::
296 The size, in bytes, that the object takes up on disk. See the
297 note about on-disk sizes in the `CAVEATS` section below.
298
65ea9c3c
JK
299`deltabase`::
300 If the object is stored as a delta on-disk, this expands to the
f4519607
DL
301 full hex representation of the delta base object name.
302 Otherwise, expands to the null OID (all zeroes). See `CAVEATS`
303 below.
65ea9c3c 304
97be0407
JK
305`rest`::
306 If this atom is used in the output string, input lines are split
307 at the first whitespace boundary. All characters before that
308 whitespace are considered to be the object name; characters
309 after that first run of whitespace (i.e., the "rest" of the
310 line) are output in place of the `%(rest)` atom.
311
93d2a607
JK
312If no format is specified, the default format is `%(objectname)
313%(objecttype) %(objectsize)`.
314
440c705e
JC
315If `--batch` is specified, or if `--batch-command` is used with the `contents`
316command, the object information is followed by the object contents (consisting
317of `%(objectsize)` bytes), followed by a newline.
93d2a607
JK
318
319For example, `--batch` without a custom format would produce:
a8128ed6
AR
320
321------------
f4519607 322<oid> SP <type> SP <size> LF
a8128ed6
AR
323<contents> LF
324------------
325
93d2a607 326Whereas `--batch-check='%(objectname) %(objecttype)'` would produce:
05d5667f
AR
327
328------------
f4519607 329<oid> SP <type> LF
05d5667f
AR
330------------
331
93d2a607
JK
332If a name is specified on stdin that cannot be resolved to an object in
333the repository, then `cat-file` will ignore any custom format and print:
2cf565c5 334
05d5667f
AR
335------------
336<object> SP missing LF
337------------
2cf565c5 338
d1dd94b3
DT
339If 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:
340
341------------
342<object> SP ambiguous LF
343------------
344
4f0ba2d5 345If `--follow-symlinks` is used, and a symlink in the repository points
122d5346
DT
346outside the repository, then `cat-file` will ignore any custom format
347and print:
348
349------------
350symlink SP <size> LF
351<symlink> LF
352------------
353
4f0ba2d5
DL
354The symlink will either be absolute (beginning with a `/`), or relative
355to the tree root. For instance, if dir/link points to `../../foo`, then
356`<symlink>` will be `../foo`. `<size>` is the size of the symlink in bytes.
122d5346 357
4f0ba2d5 358If `--follow-symlinks` is used, the following error messages will be
122d5346
DT
359displayed:
360
361------------
362<object> SP missing LF
363------------
364is printed when the initial symlink requested does not exist.
365
366------------
367dangling SP <size> LF
368<object> LF
369------------
370is printed when the initial symlink exists, but something that
371it (transitive-of) points to does not.
372
373------------
374loop SP <size> LF
375<object> LF
376------------
377is printed for symlink loops (or any symlinks that
378require more than 40 link resolutions to resolve).
379
380------------
381notdir SP <size> LF
382<object> LF
383------------
384is printed when, during symlink resolution, a file is used as a
385directory name.
a4ac1061
JK
386
387CAVEATS
388-------
389
390Note that the sizes of objects on disk are reported accurately, but care
391should be taken in drawing conclusions about which refs or objects are
392responsible for disk usage. The size of a packed non-delta object may be
393much larger than the size of objects which delta against it, but the
394choice of which object is the base and which is the delta is arbitrary
65ea9c3c 395and is subject to change during a repack.
a4ac1061 396
65ea9c3c
JK
397Note also that multiple copies of an object may be present in the object
398database; in this case, it is undefined which copy's size or delta base
399will be reported.
a4ac1061 400
2cf565c5
DG
401GIT
402---
9e1f0a85 403Part of the linkgit:git[1] suite