]>
Commit | Line | Data |
---|---|---|
2cf565c5 DG |
1 | git-cat-file(1) |
2 | =============== | |
2cf565c5 DG |
3 | |
4 | NAME | |
5 | ---- | |
cebfaaa3 | 6 | git-cat-file - Provide contents or details of repository objects |
2cf565c5 DG |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
cdf222f5 | 10 | [verse] |
97fe7250 ÆAB |
11 | 'git cat-file' <type> <object> |
12 | 'git cat-file' (-e | -p) <object> | |
83dc4434 | 13 | 'git cat-file' (-t | -s) [--allow-unknown-type] <object> |
cebfaaa3 ŠN |
14 | 'git cat-file' (--textconv | --filters) |
15 | [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>] | |
473fa2df | 16 | 'git cat-file' (--batch | --batch-check | --batch-command) [--batch-all-objects] |
97fe7250 | 17 | [--buffer] [--follow-symlinks] [--unordered] |
f79e1884 | 18 | [--textconv | --filters] [-Z] |
2cf565c5 DG |
19 | |
20 | DESCRIPTION | |
21 | ----------- | |
cebfaaa3 ŠN |
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. | |
05d5667f | 30 | |
cebfaaa3 | 31 | In batch mode, arguments are read from standard input. |
2cf565c5 DG |
32 | |
33 | OPTIONS | |
34 | ------- | |
35 | <object>:: | |
8933364d AK |
36 | The name of the object to show. |
37 | For a more complete list of ways to spell object names, see | |
9d83e382 | 38 | the "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. |
2cf565c5 DG |
39 | |
40 | -t:: | |
41 | Instead of the content, show the object type identified by | |
4f0ba2d5 | 42 | `<object>`. |
2cf565c5 | 43 | |
62bb9960 JH |
44 | -s:: |
45 | Instead of the content, show the object size identified by | |
49050a04 SA |
46 | `<object>`. If used with `--use-mailmap` option, will show |
47 | the size of updated object after replacing idents using the | |
48 | mailmap mechanism. | |
62bb9960 | 49 | |
7950571a | 50 | -e:: |
4f0ba2d5 | 51 | Exit with zero status if `<object>` exists and is a valid |
cebfaaa3 ŠN |
52 | object. If `<object>` is of an invalid format, exit with non-zero |
53 | status and emit 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 | |
a797c0ea SA |
92 | on stdin. May not be combined with any other options or arguments |
93 | except `--textconv`, `--filters`, or `--use-mailmap`. | |
8534bb4c MÅ |
94 | + |
95 | -- | |
a797c0ea SA |
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. | |
8534bb4c | 99 | |
a797c0ea SA |
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. | |
8534bb4c | 105 | -- |
a8128ed6 | 106 | |
05d5667f | 107 | --batch-check:: |
93d2a607 | 108 | --batch-check=<format>:: |
a797c0ea SA |
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`. | |
8534bb4c MÅ |
112 | + |
113 | -- | |
a797c0ea SA |
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. | |
8534bb4c | 117 | |
a797c0ea SA |
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. | |
8534bb4c | 121 | -- |
05d5667f | 122 | |
440c705e JC |
123 | --batch-command:: |
124 | --batch-command=<format>:: | |
125 | Enter a command mode that reads commands and arguments from stdin. May | |
a797c0ea SA |
126 | only be combined with `--buffer`, `--textconv`, `--use-mailmap` or |
127 | `--filters`. | |
8534bb4c MÅ |
128 | + |
129 | -- | |
a797c0ea SA |
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. | |
8534bb4c | 133 | |
a797c0ea SA |
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. | |
8534bb4c | 139 | -- |
440c705e JC |
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 | ||
6a951937 JK |
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). | |
c3660cfb JK |
164 | Requires `--batch` or `--batch-check` be specified. By default, |
165 | the objects are visited in order sorted by their hashes; see | |
5c5b29b4 JK |
166 | also `--unordered` below. Objects are presented as-is, without |
167 | respecting the "replace" mechanism of linkgit:git-replace[1]. | |
6a951937 | 168 | |
fc4937c3 JK |
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 | |
440c705e | 174 | `--batch-check` or `--batch-command` on a large number of objects. |
fc4937c3 | 175 | |
0750bb5b JK |
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 | ||
39e4ae38 | 186 | --allow-unknown-type:: |
4f0ba2d5 | 187 | Allow `-s` or `-t` to query broken/corrupt objects of unknown type. |
39e4ae38 | 188 | |
122d5346 | 189 | --follow-symlinks:: |
4f0ba2d5 | 190 | With `--batch` or `--batch-check`, follow symlinks inside the |
122d5346 DT |
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 | |
4f0ba2d5 | 195 | tree-ish (e.g. a link to `/foo` or a root-level link to `../foo`), |
122d5346 DT |
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 | ||
f79e1884 PS |
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 | ||
db9d67f2 TB |
249 | -z:: |
250 | Only meaningful with `--batch`, `--batch-check`, or | |
251 | `--batch-command`; input is NUL-delimited instead of | |
f79e1884 PS |
252 | newline-delimited. This option is deprecated in favor of |
253 | `-Z` as the output can otherwise be ambiguous. | |
db9d67f2 | 254 | |
122d5346 | 255 | |
2cf565c5 DG |
256 | OUTPUT |
257 | ------ | |
4f0ba2d5 | 258 | If `-t` is specified, one of the `<type>`. |
7950571a | 259 | |
4f0ba2d5 | 260 | If `-s` is specified, the size of the `<object>` in bytes. |
7950571a | 261 | |
4f0ba2d5 | 262 | If `-e` is specified, no output, unless the `<object>` is malformed. |
2cf565c5 | 263 | |
4f0ba2d5 | 264 | If `-p` is specified, the contents of `<object>` are pretty-printed. |
ed90cbf5 | 265 | |
4f0ba2d5 | 266 | If `<type>` is specified, the raw (though uncompressed) contents of the `<object>` |
05d5667f AR |
267 | will be returned. |
268 | ||
93d2a607 JK |
269 | BATCH OUTPUT |
270 | ------------ | |
271 | ||
272 | If `--batch` or `--batch-check` is given, `cat-file` will read objects | |
97be0407 JK |
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]. | |
93d2a607 | 276 | |
440c705e JC |
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 | ||
93d2a607 JK |
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`:: | |
f4519607 | 290 | The full hex representation of the object name. |
93d2a607 JK |
291 | |
292 | `objecttype`:: | |
be94568b | 293 | The type of the object (the same as `cat-file -t` reports). |
93d2a607 JK |
294 | |
295 | `objectsize`:: | |
296 | The size, in bytes, of the object (the same as `cat-file -s` | |
297 | reports). | |
298 | ||
a4ac1061 JK |
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 | ||
65ea9c3c JK |
303 | `deltabase`:: |
304 | If the object is stored as a delta on-disk, this expands to the | |
f4519607 DL |
305 | full hex representation of the delta base object name. |
306 | Otherwise, expands to the null OID (all zeroes). See `CAVEATS` | |
307 | below. | |
65ea9c3c | 308 | |
97be0407 JK |
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 | ||
93d2a607 JK |
316 | If no format is specified, the default format is `%(objectname) |
317 | %(objecttype) %(objectsize)`. | |
318 | ||
440c705e JC |
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. | |
93d2a607 JK |
322 | |
323 | For example, `--batch` without a custom format would produce: | |
a8128ed6 AR |
324 | |
325 | ------------ | |
f4519607 | 326 | <oid> SP <type> SP <size> LF |
a8128ed6 AR |
327 | <contents> LF |
328 | ------------ | |
329 | ||
93d2a607 | 330 | Whereas `--batch-check='%(objectname) %(objecttype)'` would produce: |
05d5667f AR |
331 | |
332 | ------------ | |
f4519607 | 333 | <oid> SP <type> LF |
05d5667f AR |
334 | ------------ |
335 | ||
93d2a607 JK |
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: | |
2cf565c5 | 338 | |
05d5667f AR |
339 | ------------ |
340 | <object> SP missing LF | |
341 | ------------ | |
2cf565c5 | 342 | |
d1dd94b3 DT |
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 | ||
4f0ba2d5 | 349 | If `--follow-symlinks` is used, and a symlink in the repository points |
122d5346 DT |
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 | ||
4f0ba2d5 DL |
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. | |
122d5346 | 361 | |
4f0ba2d5 | 362 | If `--follow-symlinks` is used, the following error messages will be |
122d5346 DT |
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. | |
a4ac1061 | 390 | |
f79e1884 PS |
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 | ||
a4ac1061 JK |
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 | |
65ea9c3c | 404 | and is subject to change during a repack. |
a4ac1061 | 405 | |
65ea9c3c JK |
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. | |
a4ac1061 | 409 | |
2cf565c5 DG |
410 | GIT |
411 | --- | |
9e1f0a85 | 412 | Part of the linkgit:git[1] suite |