1GIT-LS-TREE(1)                    Git Manual                    GIT-LS-TREE(1)
2
3
4

NAME

6       git-ls-tree - List the contents of a tree object
7

SYNOPSIS

9       git ls-tree [-d] [-r] [-t] [-l] [-z]
10                   [--name-only] [--name-status] [--object-only] [--full-name] [--full-tree] [--abbrev[=<n>]] [--format=<format>]
11                   <tree-ish> [<path>...]
12

DESCRIPTION

14       Lists the contents of a given tree object, like what "/bin/ls -a" does
15       in the current working directory. Note that:
16
17       •   the behaviour is slightly different from that of "/bin/ls" in that
18           the <path> denotes just a list of patterns to match, e.g. so
19           specifying directory name (without -r) will behave differently, and
20           order of the arguments does not matter.
21
22       •   the behaviour is similar to that of "/bin/ls" in that the <path> is
23           taken as relative to the current working directory. E.g. when you
24           are in a directory sub that has a directory dir, you can run git
25           ls-tree -r HEAD dir to list the contents of the tree (that is
26           sub/dir in HEAD). You don’t want to give a tree that is not at the
27           root level (e.g.  git ls-tree -r HEAD:sub dir) in this case, as
28           that would result in asking for sub/sub/dir in the HEAD commit.
29           However, the current working directory can be ignored by passing
30           --full-tree option.
31

OPTIONS

33       <tree-ish>
34           Id of a tree-ish.
35
36       -d
37           Show only the named tree entry itself, not its children.
38
39       -r
40           Recurse into sub-trees.
41
42       -t
43           Show tree entries even when going to recurse them. Has no effect if
44           -r was not passed.  -d implies -t.
45
46       -l, --long
47           Show object size of blob (file) entries.
48
49       -z
50           \0 line termination on output and do not quote filenames. See
51           OUTPUT FORMAT below for more information.
52
53       --name-only, --name-status
54           List only filenames (instead of the "long" output), one per line.
55           Cannot be combined with --object-only.
56
57       --object-only
58           List only names of the objects, one per line. Cannot be combined
59           with --name-only or --name-status. This is equivalent to specifying
60           --format='%(objectname)', but for both this option and that exact
61           format the command takes a hand-optimized codepath instead of going
62           through the generic formatting mechanism.
63
64       --abbrev[=<n>]
65           Instead of showing the full 40-byte hexadecimal object lines, show
66           the shortest prefix that is at least <n> hexdigits long that
67           uniquely refers the object. Non default number of digits can be
68           specified with --abbrev=<n>.
69
70       --full-name
71           Instead of showing the path names relative to the current working
72           directory, show the full path names.
73
74       --full-tree
75           Do not limit the listing to the current working directory. Implies
76           --full-name.
77
78       --format=<format>
79           A string that interpolates %(fieldname) from the result being
80           shown. It also interpolates %% to %, and %xNN where NN are hex
81           digits interpolates to character with hex code NN; for example %x00
82           interpolates to \0 (NUL), %x09 to \t (TAB) and %x0a to \n (LF).
83           When specified, --format cannot be combined with other
84           format-altering options, including --long, --name-only and
85           --object-only.
86
87       [<path>...]
88           When paths are given, show them (note that this isn’t really raw
89           pathnames, but rather a list of patterns to match). Otherwise
90           implicitly uses the root level of the tree as the sole path
91           argument.
92

OUTPUT FORMAT

94       The output format of ls-tree is determined by either the --format
95       option, or other format-altering options such as --name-only etc. (see
96       --format above).
97
98       The use of certain --format directives is equivalent to using those
99       options, but invoking the full formatting machinery can be slower than
100       using an appropriate formatting option.
101
102       In cases where the --format would exactly map to an existing option
103       ls-tree will use the appropriate faster path. Thus the default format
104       is equivalent to:
105
106           %(objectmode) %(objecttype) %(objectname)%x09%(path)
107
108       This output format is compatible with what --index-info --stdin of git
109       update-index expects.
110
111       When the -l option is used, format changes to
112
113           %(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)
114
115       Object size identified by <objectname> is given in bytes, and
116       right-justified with minimum width of 7 characters. Object size is
117       given only for blobs (file) entries; for other entries - character is
118       used in place of size.
119
120       Without the -z option, pathnames with "unusual" characters are quoted
121       as explained for the configuration variable core.quotePath (see git-
122       config(1)). Using -z the filename is output verbatim and the line is
123       terminated by a NUL byte.
124
125       Customized format:
126
127       It is possible to print in a custom format by using the --format
128       option, which is able to interpolate different fields using a
129       %(fieldname) notation. For example, if you only care about the
130       "objectname" and "path" fields, you can execute with a specific
131       "--format" like
132
133           git ls-tree --format='%(objectname) %(path)' <tree-ish>
134

FIELD NAMES

136       Various values from structured fields can be used to interpolate into
137       the resulting output. For each outputting line, the following names can
138       be used:
139
140       objectmode
141           The mode of the object.
142
143       objecttype
144           The type of the object (commit, blob or tree).
145
146       objectname
147           The name of the object.
148
149       objectsize[:padded]
150           The size of a blob object ("-" if it’s a commit or tree). It also
151           supports a padded format of size with "%(objectsize:padded)".
152
153       path
154           The pathname of the object.
155

GIT

157       Part of the git(1) suite
158
159
160
161Git 2.43.0                        11/20/2023                    GIT-LS-TREE(1)
Impressum