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