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