1GIT-CAT-FILE(1) Git Manual GIT-CAT-FILE(1)
2
3
4
6 git-cat-file - Provide content or type and size information for
7 repository objects
8
10 git cat-file <type> <object>
11 git cat-file (-e | -p) <object>
12 git cat-file (-t | -s) [--allow-unknown-type] <object>
13 git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects]
14 [--buffer] [--follow-symlinks] [--unordered]
15 [--textconv | --filters]
16 git cat-file (--textconv | --filters)
17 [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
18
20 In its first form, the command provides the content or the type of an
21 object in the repository. The type is required unless -t or -p is used
22 to find the object type, or -s is used to find the object size, or
23 --textconv or --filters is used (which imply type "blob").
24
25 In the second form, a list of objects (separated by linefeeds) is
26 provided on stdin, and the SHA-1, type, and size of each object is
27 printed on stdout. The output format can be overridden using the
28 optional <format> argument. If either --textconv or --filters was
29 specified, the input is expected to list the object names followed by
30 the path name, separated by a single whitespace, so that the
31 appropriate drivers can be determined.
32
34 <object>
35 The name of the object to show. For a more complete list of ways to
36 spell object names, see the "SPECIFYING REVISIONS" section in
37 gitrevisions(7).
38
39 -t
40 Instead of the content, show the object type identified by
41 <object>.
42
43 -s
44 Instead of the content, show the object size identified by
45 <object>.
46
47 -e
48 Exit with zero status if <object> exists and is a valid object. If
49 <object> is of an invalid format exit with non-zero and emits an
50 error on stderr.
51
52 -p
53 Pretty-print the contents of <object> based on its type.
54
55 <type>
56 Typically this matches the real type of <object> but asking for a
57 type that can trivially be dereferenced from the given <object> is
58 also permitted. An example is to ask for a "tree" with <object>
59 being a commit object that contains it, or to ask for a "blob" with
60 <object> being a tag object that points at it.
61
62 --textconv
63 Show the content as transformed by a textconv filter. In this case,
64 <object> has to be of the form <tree-ish>:<path>, or :<path> in
65 order to apply the filter to the content recorded in the index at
66 <path>.
67
68 --filters
69 Show the content as converted by the filters configured in the
70 current working tree for the given <path> (i.e. smudge filters,
71 end-of-line conversion, etc). In this case, <object> has to be of
72 the form <tree-ish>:<path>, or :<path>.
73
74 --path=<path>
75 For use with --textconv or --filters, to allow specifying an object
76 name and a path separately, e.g. when it is difficult to figure out
77 the revision from which the blob came.
78
79 --batch, --batch=<format>
80 Print object information and contents for each object provided on
81 stdin. May not be combined with any other options or arguments
82 except --textconv or --filters, in which case the input lines also
83 need to specify the path, separated by whitespace. See the section
84 BATCH OUTPUT below for details.
85
86 --batch-check, --batch-check=<format>
87 Print object information for each object provided on stdin. May not
88 be combined with any other options or arguments except --textconv
89 or --filters, in which case the input lines also need to specify
90 the path, separated by whitespace. See the section BATCH OUTPUT
91 below for details.
92
93 --batch-command, --batch-command=<format>
94 Enter a command mode that reads commands and arguments from stdin.
95 May only be combined with --buffer, --textconv or --filters. In the
96 case of --textconv or --filters, the input lines also need to
97 specify the path, separated by whitespace. See the section BATCH
98 OUTPUT below for details.
99
100 --batch-command recognizes the following commands:
101
102 contents <object>
103 Print object contents for object reference <object>. This
104 corresponds to the output of --batch.
105
106 info <object>
107 Print object info for object reference <object>. This
108 corresponds to the output of --batch-check.
109
110 flush
111 Used with --buffer to execute all preceding commands that were
112 issued since the beginning or since the last flush was issued.
113 When --buffer is used, no output will come until a flush is
114 issued. When --buffer is not used, commands are flushed each
115 time without issuing flush.
116
117 --batch-all-objects
118 Instead of reading a list of objects on stdin, perform the
119 requested batch operation on all objects in the repository and any
120 alternate object stores (not just reachable objects). Requires
121 --batch or --batch-check be specified. By default, the objects are
122 visited in order sorted by their hashes; see also --unordered
123 below. Objects are presented as-is, without respecting the
124 "replace" mechanism of git-replace(1).
125
126 --buffer
127 Normally batch output is flushed after each object is output, so
128 that a process can interactively read and write from cat-file. With
129 this option, the output uses normal stdio buffering; this is much
130 more efficient when invoking --batch-check or --batch-command on a
131 large number of objects.
132
133 --unordered
134 When --batch-all-objects is in use, visit objects in an order which
135 may be more efficient for accessing the object contents than hash
136 order. The exact details of the order are unspecified, but if you
137 do not require a specific order, this should generally result in
138 faster output, especially with --batch. Note that cat-file will
139 still show each object only once, even if it is stored multiple
140 times in the repository.
141
142 --allow-unknown-type
143 Allow -s or -t to query broken/corrupt objects of unknown type.
144
145 --follow-symlinks
146 With --batch or --batch-check, follow symlinks inside the
147 repository when requesting objects with extended SHA-1 expressions
148 of the form tree-ish:path-in-tree. Instead of providing output
149 about the link itself, provide output about the linked-to object.
150 If a symlink points outside the tree-ish (e.g. a link to /foo or a
151 root-level link to ../foo), the portion of the link which is
152 outside the tree will be printed.
153
154 This option does not (currently) work correctly when an object in
155 the index is specified (e.g. :link instead of HEAD:link) rather
156 than one in the tree.
157
158 This option cannot (currently) be used unless --batch or
159 --batch-check is used.
160
161 For example, consider a git repository containing:
162
163 f: a file containing "hello\n"
164 link: a symlink to f
165 dir/link: a symlink to ../f
166 plink: a symlink to ../f
167 alink: a symlink to /etc/passwd
168
169 For a regular file f, echo HEAD:f | git cat-file --batch would
170 print
171
172 ce013625030ba8dba906f756967f9e9ca394464a blob 6
173
174 And echo HEAD:link | git cat-file --batch --follow-symlinks would
175 print the same thing, as would HEAD:dir/link, as they both point at
176 HEAD:f.
177
178 Without --follow-symlinks, these would print data about the symlink
179 itself. In the case of HEAD:link, you would see
180
181 4d1ae35ba2c8ec712fa2a379db44ad639ca277bd blob 1
182
183 Both plink and alink point outside the tree, so they would
184 respectively print:
185
186 symlink 4
187 ../f
188
189 symlink 11
190 /etc/passwd
191
193 If -t is specified, one of the <type>.
194
195 If -s is specified, the size of the <object> in bytes.
196
197 If -e is specified, no output, unless the <object> is malformed.
198
199 If -p is specified, the contents of <object> are pretty-printed.
200
201 If <type> is specified, the raw (though uncompressed) contents of the
202 <object> will be returned.
203
205 If --batch or --batch-check is given, cat-file will read objects from
206 stdin, one per line, and print information about them. By default, the
207 whole line is considered as an object, as if it were fed to git-rev-
208 parse(1).
209
210 When --batch-command is given, cat-file will read commands from stdin,
211 one per line, and print information based on the command given. With
212 --batch-command, the info command followed by an object will print
213 information about the object the same way --batch-check would, and the
214 contents command followed by an object prints contents in the same way
215 --batch would.
216
217 You can specify the information shown for each object by using a custom
218 <format>. The <format> is copied literally to stdout for each object,
219 with placeholders of the form %(atom) expanded, followed by a newline.
220 The available atoms are:
221
222 objectname
223 The full hex representation of the object name.
224
225 objecttype
226 The type of the object (the same as cat-file -t reports).
227
228 objectsize
229 The size, in bytes, of the object (the same as cat-file -s
230 reports).
231
232 objectsize:disk
233 The size, in bytes, that the object takes up on disk. See the note
234 about on-disk sizes in the CAVEATS section below.
235
236 deltabase
237 If the object is stored as a delta on-disk, this expands to the
238 full hex representation of the delta base object name. Otherwise,
239 expands to the null OID (all zeroes). See CAVEATS below.
240
241 rest
242 If this atom is used in the output string, input lines are split at
243 the first whitespace boundary. All characters before that
244 whitespace are considered to be the object name; characters after
245 that first run of whitespace (i.e., the "rest" of the line) are
246 output in place of the %(rest) atom.
247
248 If no format is specified, the default format is %(objectname)
249 %(objecttype) %(objectsize).
250
251 If --batch is specified, or if --batch-command is used with the
252 contents command, the object information is followed by the object
253 contents (consisting of %(objectsize) bytes), followed by a newline.
254
255 For example, --batch without a custom format would produce:
256
257 <oid> SP <type> SP <size> LF
258 <contents> LF
259
260 Whereas --batch-check='%(objectname) %(objecttype)' would produce:
261
262 <oid> SP <type> LF
263
264 If a name is specified on stdin that cannot be resolved to an object in
265 the repository, then cat-file will ignore any custom format and print:
266
267 <object> SP missing LF
268
269 If a name is specified that might refer to more than one object (an
270 ambiguous short sha), then cat-file will ignore any custom format and
271 print:
272
273 <object> SP ambiguous LF
274
275 If --follow-symlinks is used, and a symlink in the repository points
276 outside the repository, then cat-file will ignore any custom format and
277 print:
278
279 symlink SP <size> LF
280 <symlink> LF
281
282 The symlink will either be absolute (beginning with a /), or relative
283 to the tree root. For instance, if dir/link points to ../../foo, then
284 <symlink> will be ../foo. <size> is the size of the symlink in bytes.
285
286 If --follow-symlinks is used, the following error messages will be
287 displayed:
288
289 <object> SP missing LF
290
291 is printed when the initial symlink requested does not exist.
292
293 dangling SP <size> LF
294 <object> LF
295
296 is printed when the initial symlink exists, but something that it
297 (transitive-of) points to does not.
298
299 loop SP <size> LF
300 <object> LF
301
302 is printed for symlink loops (or any symlinks that require more than 40
303 link resolutions to resolve).
304
305 notdir SP <size> LF
306 <object> LF
307
308 is printed when, during symlink resolution, a file is used as a
309 directory name.
310
312 Note that the sizes of objects on disk are reported accurately, but
313 care should be taken in drawing conclusions about which refs or objects
314 are responsible for disk usage. The size of a packed non-delta object
315 may be much larger than the size of objects which delta against it, but
316 the choice of which object is the base and which is the delta is
317 arbitrary and is subject to change during a repack.
318
319 Note also that multiple copies of an object may be present in the
320 object database; in this case, it is undefined which copy’s size or
321 delta base will be reported.
322
324 Part of the git(1) suite
325
326
327
328Git 2.36.1 2022-05-05 GIT-CAT-FILE(1)