blob: 4eb0421b3fd946e709318d835783530bb89e7caa [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-cat-file(1)
2===============
3
4NAME
5----
Junio C Hamano1de75722009-03-26 08:39:386git-cat-file - Provide content or type and size information for repository objects
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamanodc8f25b2008-06-11 07:52:2811[verse]
Junio C Hamano53800482016-09-21 23:26:4312'git cat-file' (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | <type> | --textconv | --filters ) [--path=<path>] <object>
Junio C Hamano096c5cf2020-07-09 21:30:3713'git cat-file' (--batch[=<format>] | --batch-check[=<format>]) [ --textconv | --filters ] [--follow-symlinks]
Junio C Hamano1a4e8412005-12-27 08:17:2314
15DESCRIPTION
16-----------
Junio C Hamano1de75722009-03-26 08:39:3817In its first form, the command provides the content or the type of an object in
Junio C Hamano92d80372016-07-13 22:00:0518the repository. The type is required unless `-t` or `-p` is used to find the
Junio C Hamano53800482016-09-21 23:26:4319object type, or `-s` is used to find the object size, or `--textconv` or
20`--filters` is used (which imply type "blob").
Junio C Hamanodfccbb02008-05-26 01:16:1421
Junio C Hamano1de75722009-03-26 08:39:3822In the second form, a list of objects (separated by linefeeds) is provided on
Junio C Hamano53800482016-09-21 23:26:4323stdin, and the SHA-1, type, and size of each object is printed on stdout. The
24output format can be overridden using the optional `<format>` argument. If
25either `--textconv` or `--filters` was specified, the input is expected to
Junio C Hamanoa90214f2019-01-28 22:05:2526list the object names followed by the path name, separated by a single
27whitespace, so that the appropriate drivers can be determined.
Junio C Hamano1a4e8412005-12-27 08:17:2328
29OPTIONS
30-------
31<object>::
Junio C Hamano8f62db92007-02-01 00:22:2232The name of the object to show.
33For a more complete list of ways to spell object names, see
Junio C Hamanoc27b7332010-10-14 04:37:2834the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
Junio C Hamano1a4e8412005-12-27 08:17:2335
36-t::
37Instead of the content, show the object type identified by
Junio C Hamano458281a2021-03-22 21:20:2638`<object>`.
Junio C Hamano1a4e8412005-12-27 08:17:2339
40-s::
41Instead of the content, show the object size identified by
Junio C Hamano458281a2021-03-22 21:20:2642`<object>`.
Junio C Hamano1a4e8412005-12-27 08:17:2343
44-e::
Junio C Hamano458281a2021-03-22 21:20:2645Exit with zero status if `<object>` exists and is a valid
46object. If `<object>` is of an invalid format exit with non-zero and
Junio C Hamano7b9cce92018-01-23 22:34:2747emits an error on stderr.
Junio C Hamano1a4e8412005-12-27 08:17:2348
Junio C Hamano8eb323c2006-05-25 05:55:2249-p::
Junio C Hamano458281a2021-03-22 21:20:2650Pretty-print the contents of `<object>` based on its type.
Junio C Hamano8eb323c2006-05-25 05:55:2251
Junio C Hamano1a4e8412005-12-27 08:17:2352<type>::
Junio C Hamano458281a2021-03-22 21:20:2653Typically this matches the real type of `<object>` but asking
Junio C Hamano1a4e8412005-12-27 08:17:2354for a type that can trivially be dereferenced from the given
Junio C Hamano458281a2021-03-22 21:20:2655`<object>` is also permitted. An example is to ask for a
56"tree" with `<object>` being a commit object that contains it,
57or to ask for a "blob" with `<object>` being a tag object that
Junio C Hamano1a4e8412005-12-27 08:17:2358points at it.
59
Junio C Hamano4015aed2010-06-27 20:07:4260--textconv::
61Show the content as transformed by a textconv filter. In this case,
Junio C Hamano458281a2021-03-22 21:20:2662`<object>` has to be of the form `<tree-ish>:<path>`, or `:<path>` in
Junio C Hamano53800482016-09-21 23:26:4363order to apply the filter to the content recorded in the index at
Junio C Hamano458281a2021-03-22 21:20:2664`<path>`.
Junio C Hamano53800482016-09-21 23:26:4365
66--filters::
67Show the content as converted by the filters configured in
Junio C Hamano458281a2021-03-22 21:20:2668the current working tree for the given `<path>` (i.e. smudge filters,
69end-of-line conversion, etc). In this case, `<object>` has to be of
70the form `<tree-ish>:<path>`, or `:<path>`.
Junio C Hamano53800482016-09-21 23:26:4371
72--path=<path>::
Junio C Hamano458281a2021-03-22 21:20:2673For use with `--textconv` or `--filters`, to allow specifying an object
Junio C Hamano53800482016-09-21 23:26:4374name and a path separately, e.g. when it is difficult to figure out
75the revision from which the blob came.
Junio C Hamano4015aed2010-06-27 20:07:4276
Junio C Hamanodfccbb02008-05-26 01:16:1477--batch::
Junio C Hamano0f578a72013-07-19 00:36:4578--batch=<format>::
79Print object information and contents for each object provided
Junio C Hamano53800482016-09-21 23:26:4380on stdin. May not be combined with any other options or arguments
81except `--textconv` or `--filters`, in which case the input lines
Junio C Hamanoa90214f2019-01-28 22:05:2582also need to specify the path, separated by whitespace. See the
Junio C Hamano53800482016-09-21 23:26:4383section `BATCH OUTPUT` below for details.
Junio C Hamanodfccbb02008-05-26 01:16:1484
85--batch-check::
Junio C Hamano0f578a72013-07-19 00:36:4586--batch-check=<format>::
87Print object information for each object provided on stdin. May
Junio C Hamano53800482016-09-21 23:26:4388not be combined with any other options or arguments except
89`--textconv` or `--filters`, in which case the input lines also
Junio C Hamanoa90214f2019-01-28 22:05:2590need to specify the path, separated by whitespace. See the
Junio C Hamano0f578a72013-07-19 00:36:4591section `BATCH OUTPUT` below for details.
Junio C Hamanodfccbb02008-05-26 01:16:1492
Junio C Hamanod7ed4042015-08-03 19:43:0093--batch-all-objects::
94Instead of reading a list of objects on stdin, perform the
95requested batch operation on all objects in the repository and
96any alternate object stores (not just reachable objects).
97Requires `--batch` or `--batch-check` be specified. Note that
98the objects are visited in order sorted by their hashes.
99
100--buffer::
101Normally batch output is flushed after each object is output, so
102that a process can interactively read and write from
103`cat-file`. With this option, the output uses normal stdio
104buffering; this is much more efficient when invoking
105`--batch-check` on a large number of objects.
106
Junio C Hamano11ae3202018-08-20 20:15:42107--unordered::
108When `--batch-all-objects` is in use, visit objects in an
109order which may be more efficient for accessing the object
110contents than hash order. The exact details of the order are
111unspecified, but if you do not require a specific order, this
112should generally result in faster output, especially with
113`--batch`. Note that `cat-file` will still show each object
114only once, even if it is stored multiple times in the
115repository.
116
Junio C Hamanoe1b28592015-05-19 21:26:17117--allow-unknown-type::
Junio C Hamano458281a2021-03-22 21:20:26118Allow `-s` or `-t` to query broken/corrupt objects of unknown type.
Junio C Hamanoe1b28592015-05-19 21:26:17119
Junio C Hamano85f1fde2015-06-01 20:37:32120--follow-symlinks::
Junio C Hamano458281a2021-03-22 21:20:26121With `--batch` or `--batch-check`, follow symlinks inside the
Junio C Hamano85f1fde2015-06-01 20:37:32122repository when requesting objects with extended SHA-1
123expressions of the form tree-ish:path-in-tree. Instead of
124providing output about the link itself, provide output about
125the linked-to object. If a symlink points outside the
Junio C Hamano458281a2021-03-22 21:20:26126tree-ish (e.g. a link to `/foo` or a root-level link to `../foo`),
Junio C Hamano85f1fde2015-06-01 20:37:32127the portion of the link which is outside the tree will be
128printed.
129+
130This option does not (currently) work correctly when an object in the
131index is specified (e.g. `:link` instead of `HEAD:link`) rather than
132one in the tree.
133+
134This option cannot (currently) be used unless `--batch` or
135`--batch-check` is used.
136+
137For example, consider a git repository containing:
138+
139--
140f: a file containing "hello\n"
141link: a symlink to f
142dir/link: a symlink to ../f
143plink: a symlink to ../f
144alink: a symlink to /etc/passwd
145--
146+
147For a regular file `f`, `echo HEAD:f | git cat-file --batch` would print
148+
149--
150ce013625030ba8dba906f756967f9e9ca394464a blob 6
151--
152+
153And `echo HEAD:link | git cat-file --batch --follow-symlinks` would
154print the same thing, as would `HEAD:dir/link`, as they both point at
155`HEAD:f`.
156+
157Without `--follow-symlinks`, these would print data about the symlink
158itself. In the case of `HEAD:link`, you would see
159+
160--
1614d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
162--
163+
164Both `plink` and `alink` point outside the tree, so they would
165respectively print:
166+
167--
168symlink 4
169../f
170
171symlink 11
172/etc/passwd
173--
174
175
Junio C Hamano1a4e8412005-12-27 08:17:23176OUTPUT
177------
Junio C Hamano458281a2021-03-22 21:20:26178If `-t` is specified, one of the `<type>`.
Junio C Hamano1a4e8412005-12-27 08:17:23179
Junio C Hamano458281a2021-03-22 21:20:26180If `-s` is specified, the size of the `<object>` in bytes.
Junio C Hamano1a4e8412005-12-27 08:17:23181
Junio C Hamano458281a2021-03-22 21:20:26182If `-e` is specified, no output, unless the `<object>` is malformed.
Junio C Hamano1a4e8412005-12-27 08:17:23183
Junio C Hamano458281a2021-03-22 21:20:26184If `-p` is specified, the contents of `<object>` are pretty-printed.
Junio C Hamano8eb323c2006-05-25 05:55:22185
Junio C Hamano458281a2021-03-22 21:20:26186If `<type>` is specified, the raw (though uncompressed) contents of the `<object>`
Junio C Hamanodfccbb02008-05-26 01:16:14187will be returned.
Junio C Hamano1a4e8412005-12-27 08:17:23188
Junio C Hamano0f578a72013-07-19 00:36:45189BATCH OUTPUT
190------------
191
192If `--batch` or `--batch-check` is given, `cat-file` will read objects
Junio C Hamano8eac2682013-09-09 22:35:20193from stdin, one per line, and print information about them. By default,
194the whole line is considered as an object, as if it were fed to
195linkgit:git-rev-parse[1].
Junio C Hamano0f578a72013-07-19 00:36:45196
197You can specify the information shown for each object by using a custom
198`<format>`. The `<format>` is copied literally to stdout for each
199object, with placeholders of the form `%(atom)` expanded, followed by a
200newline. The available atoms are:
201
202`objectname`::
Junio C Hamano458281a2021-03-22 21:20:26203The full hex representation of the object name.
Junio C Hamano0f578a72013-07-19 00:36:45204
205`objecttype`::
Junio C Hamanod4bbec02017-09-25 07:24:53206The type of the object (the same as `cat-file -t` reports).
Junio C Hamano0f578a72013-07-19 00:36:45207
208`objectsize`::
209The size, in bytes, of the object (the same as `cat-file -s`
210reports).
211
212`objectsize:disk`::
213The size, in bytes, that the object takes up on disk. See the
214note about on-disk sizes in the `CAVEATS` section below.
215
Junio C Hamano21bc18b2014-01-10 20:33:07216`deltabase`::
217If the object is stored as a delta on-disk, this expands to the
Junio C Hamano458281a2021-03-22 21:20:26218full hex representation of the delta base object name.
219Otherwise, expands to the null OID (all zeroes). See `CAVEATS`
220below.
Junio C Hamano21bc18b2014-01-10 20:33:07221
Junio C Hamano8eac2682013-09-09 22:35:20222`rest`::
223If this atom is used in the output string, input lines are split
224at the first whitespace boundary. All characters before that
225whitespace are considered to be the object name; characters
226after that first run of whitespace (i.e., the "rest" of the
227line) are output in place of the `%(rest)` atom.
228
Junio C Hamano0f578a72013-07-19 00:36:45229If no format is specified, the default format is `%(objectname)
230%(objecttype) %(objectsize)`.
231
232If `--batch` is specified, the object information is followed by the
233object contents (consisting of `%(objectsize)` bytes), followed by a
234newline.
235
236For example, `--batch` without a custom format would produce:
Junio C Hamanodfccbb02008-05-26 01:16:14237
238------------
Junio C Hamano458281a2021-03-22 21:20:26239<oid> SP <type> SP <size> LF
Junio C Hamanodfccbb02008-05-26 01:16:14240<contents> LF
241------------
242
Junio C Hamano0f578a72013-07-19 00:36:45243Whereas `--batch-check='%(objectname) %(objecttype)'` would produce:
Junio C Hamanodfccbb02008-05-26 01:16:14244
245------------
Junio C Hamano458281a2021-03-22 21:20:26246<oid> SP <type> LF
Junio C Hamanodfccbb02008-05-26 01:16:14247------------
248
Junio C Hamano0f578a72013-07-19 00:36:45249If a name is specified on stdin that cannot be resolved to an object in
250the repository, then `cat-file` will ignore any custom format and print:
Junio C Hamanodfccbb02008-05-26 01:16:14251
252------------
253<object> SP missing LF
254------------
Junio C Hamano1a4e8412005-12-27 08:17:23255
Junio C Hamano23168ef2019-02-07 07:20:47256If 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:
257
258------------
259<object> SP ambiguous LF
260------------
261
Junio C Hamano458281a2021-03-22 21:20:26262If `--follow-symlinks` is used, and a symlink in the repository points
Junio C Hamano85f1fde2015-06-01 20:37:32263outside the repository, then `cat-file` will ignore any custom format
264and print:
265
266------------
267symlink SP <size> LF
268<symlink> LF
269------------
270
Junio C Hamano458281a2021-03-22 21:20:26271The symlink will either be absolute (beginning with a `/`), or relative
272to the tree root. For instance, if dir/link points to `../../foo`, then
273`<symlink>` will be `../foo`. `<size>` is the size of the symlink in bytes.
Junio C Hamano85f1fde2015-06-01 20:37:32274
Junio C Hamano458281a2021-03-22 21:20:26275If `--follow-symlinks` is used, the following error messages will be
Junio C Hamano85f1fde2015-06-01 20:37:32276displayed:
277
278------------
279<object> SP missing LF
280------------
281is printed when the initial symlink requested does not exist.
282
283------------
284dangling SP <size> LF
285<object> LF
286------------
287is printed when the initial symlink exists, but something that
288it (transitive-of) points to does not.
289
290------------
291loop SP <size> LF
292<object> LF
293------------
294is printed for symlink loops (or any symlinks that
295require more than 40 link resolutions to resolve).
296
297------------
298notdir SP <size> LF
299<object> LF
300------------
301is printed when, during symlink resolution, a file is used as a
302directory name.
Junio C Hamano0f578a72013-07-19 00:36:45303
304CAVEATS
305-------
306
307Note that the sizes of objects on disk are reported accurately, but care
308should be taken in drawing conclusions about which refs or objects are
309responsible for disk usage. The size of a packed non-delta object may be
310much larger than the size of objects which delta against it, but the
311choice of which object is the base and which is the delta is arbitrary
Junio C Hamano21bc18b2014-01-10 20:33:07312and is subject to change during a repack.
Junio C Hamano0f578a72013-07-19 00:36:45313
Junio C Hamano21bc18b2014-01-10 20:33:07314Note also that multiple copies of an object may be present in the object
315database; in this case, it is undefined which copy's size or delta base
316will be reported.
Junio C Hamano0f578a72013-07-19 00:36:45317
Junio C Hamano1a4e8412005-12-27 08:17:23318GIT
319---
Junio C Hamanof7c042d2008-06-06 22:50:53320Part of the linkgit:git[1] suite