]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-ls-tree.txt
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / Documentation / git-ls-tree.txt
CommitLineData
2cf565c5
DG
1git-ls-tree(1)
2==============
2cf565c5
DG
3
4NAME
5----
c3f0baac 6git-ls-tree - List the contents of a tree object
2cf565c5
DG
7
8
9SYNOPSIS
10--------
fd7e9fb7 11[verse]
b1889c36 12'git ls-tree' [-d] [-r] [-t] [-l] [-z]
cab851c2 13 [--name-only] [--name-status] [--object-only] [--full-name] [--full-tree] [--abbrev[=<n>]] [--format=<format>]
62b4698e 14 <tree-ish> [<path>...]
2cf565c5
DG
15
16DESCRIPTION
17-----------
7b9b4c45 18Lists the contents of a given tree object, like what "/bin/ls -a" does
7ddea13a
JH
19in the current working directory. Note that:
20
21 - the behaviour is slightly different from that of "/bin/ls" in that the
62b4698e 22 '<path>' denotes just a list of patterns to match, e.g. so specifying
23f8239b 23 directory name (without `-r`) will behave differently, and order of the
7ddea13a
JH
24 arguments does not matter.
25
62b4698e 26 - the behaviour is similar to that of "/bin/ls" in that the '<path>' is
7ddea13a
JH
27 taken as relative to the current working directory. E.g. when you are
28 in a directory 'sub' that has a directory 'dir', you can run 'git
29 ls-tree -r HEAD dir' to list the contents of the tree (that is
68ed71b5 30 `sub/dir` in `HEAD`). You don't want to give a tree that is not at the
ca768288 31 root level (e.g. `git ls-tree -r HEAD:sub dir`) in this case, as that
68ed71b5 32 would result in asking for `sub/sub/dir` in the `HEAD` commit.
e1a59774
NS
33 However, the current working directory can be ignored by passing
34 --full-tree option.
2cf565c5
DG
35
36OPTIONS
37-------
38<tree-ish>::
2c6e4771 39 Id of a tree-ish.
2cf565c5 40
6af1f019 41-d::
7b9b4c45 42 Show only the named tree entry itself, not its children.
6af1f019 43
2cf565c5 44-r::
7b9b4c45
PB
45 Recurse into sub-trees.
46
47-t::
48 Show tree entries even when going to recurse them. Has no effect
23f8239b 49 if `-r` was not passed. `-d` implies `-t`.
2cf565c5 50
a5bbda8b
JN
51-l::
52--long::
53 Show object size of blob (file) entries.
54
2cf565c5 55-z::
860cd699
AH
56 \0 line termination on output and do not quote filenames.
57 See OUTPUT FORMAT below for more information.
7b9b4c45
PB
58
59--name-only::
60--name-status::
61 List only filenames (instead of the "long" output), one per line.
cab851c2
TL
62 Cannot be combined with `--object-only`.
63
64--object-only::
65 List only names of the objects, one per line. Cannot be combined
66 with `--name-only` or `--name-status`.
67 This is equivalent to specifying `--format='%(objectname)'`, but
68 for both this option and that exact format the command takes a
69 hand-optimized codepath instead of going through the generic
70 formatting mechanism.
2cf565c5 71
cb85bfe5
EW
72--abbrev[=<n>]::
73 Instead of showing the full 40-byte hexadecimal object
cda34e0d
JH
74 lines, show the shortest prefix that is at least '<n>'
75 hexdigits long that uniquely refers the object.
cb85bfe5
EW
76 Non default number of digits can be specified with --abbrev=<n>.
77
fd7e9fb7 78--full-name::
42698220 79 Instead of showing the path names relative to the current working
fd7e9fb7
JF
80 directory, show the full path names.
81
e1a59774
NS
82--full-tree::
83 Do not limit the listing to the current working directory.
84 Implies --full-name.
85
455923e0
ÆAB
86--format=<format>::
87 A string that interpolates `%(fieldname)` from the result
88 being shown. It also interpolates `%%` to `%`, and
89 `%xx` where `xx` are hex digits interpolates to character
90 with hex code `xx`; for example `%00` interpolates to
91 `\0` (NUL), `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
92 When specified, `--format` cannot be combined with other
93 format-altering options, including `--long`, `--name-only`
94 and `--object-only`.
95
62b4698e 96[<path>...]::
7b9b4c45
PB
97 When paths are given, show them (note that this isn't really raw
98 pathnames, but rather a list of patterns to match). Otherwise
99 implicitly uses the root level of the tree as the sole path argument.
6af1f019 100
6d3a5077 101
2cf565c5
DG
102Output Format
103-------------
455923e0
ÆAB
104
105The output format of `ls-tree` is determined by either the `--format`
106option, or other format-altering options such as `--name-only` etc.
107(see `--format` above).
108
109The use of certain `--format` directives is equivalent to using those
110options, but invoking the full formatting machinery can be slower than
111using an appropriate formatting option.
112
113In cases where the `--format` would exactly map to an existing option
114`ls-tree` will use the appropriate faster path. Thus the default format
115is equivalent to:
116
117 %(objectmode) %(objecttype) %(objectname)%x09%(path)
2cf565c5 118
ca768288 119This output format is compatible with what `--index-info --stdin` of
c98a95ee 120'git update-index' expects.
d88156e9 121
a5bbda8b
JN
122When the `-l` option is used, format changes to
123
455923e0 124 %(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)
a5bbda8b 125
455923e0 126Object size identified by <objectname> is given in bytes, and right-justified
a5bbda8b
JN
127with minimum width of 7 characters. Object size is given only for blobs
128(file) entries; for other entries `-` character is used in place of size.
129
860cd699
AH
130Without the `-z` option, pathnames with "unusual" characters are
131quoted as explained for the configuration variable `core.quotePath`
132(see linkgit:git-config[1]). Using `-z` the filename is output
133verbatim and the line is terminated by a NUL byte.
134
455923e0
ÆAB
135Customized format:
136
137It is possible to print in a custom format by using the `--format` option,
138which is able to interpolate different fields using a `%(fieldname)` notation.
139For example, if you only care about the "objectname" and "path" fields, you
140can execute with a specific "--format" like
141
142 git ls-tree --format='%(objectname) %(path)' <tree-ish>
143
144FIELD NAMES
145-----------
146
147Various values from structured fields can be used to interpolate
148into the resulting output. For each outputing line, the following
149names can be used:
150
151objectmode::
152 The mode of the object.
153objecttype::
154 The type of the object (`blob` or `tree`).
155objectname::
156 The name of the object.
157objectsize[:padded]::
158 The size of the object ("-" if it's a tree).
159 It also supports a padded format of size with "%(size:padded)".
160path::
161 The pathname of the object.
162
2cf565c5
DG
163GIT
164---
9e1f0a85 165Part of the linkgit:git[1] suite