summaryrefslogtreecommitdiffstats
path: root/man1/git-ls-tree.1
blob: 01af6af341bf0c52b007fb606c4d9a03eca6192d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
'\" t
.\"     Title: git-ls-tree
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2024-04-19
.\"    Manual: Git Manual
.\"    Source: Git 2.45.0.rc0
.\"  Language: English
.\"
.TH "GIT\-LS\-TREE" "1" "2024\-04\-19" "Git 2\&.45\&.0\&.rc0" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-ls-tree \- List the contents of a tree object
.SH "SYNOPSIS"
.sp
.nf
\fIgit ls\-tree\fR [\-d] [\-r] [\-t] [\-l] [\-z]
            [\-\-name\-only] [\-\-name\-status] [\-\-object\-only] [\-\-full\-name] [\-\-full\-tree] [\-\-abbrev[=<n>]] [\-\-format=<format>]
            <tree\-ish> [<path>\&...]
.fi
.sp
.SH "DESCRIPTION"
.sp
Lists the contents of a given tree object, like what "/bin/ls \-a" does in the current working directory\&. Note that:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
the behaviour is slightly different from that of "/bin/ls" in that the
\fI<path>\fR
denotes just a list of patterns to match, e\&.g\&. so specifying directory name (without
\fB\-r\fR) will behave differently, and order of the arguments does not matter\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
the behaviour is similar to that of "/bin/ls" in that the
\fI<path>\fR
is taken as relative to the current working directory\&. E\&.g\&. when you are in a directory
\fIsub\fR
that has a directory
\fIdir\fR, you can run
\fIgit ls\-tree \-r HEAD dir\fR
to list the contents of the tree (that is
\fBsub/dir\fR
in
\fBHEAD\fR)\&. You don\(cqt want to give a tree that is not at the root level (e\&.g\&.
\fBgit ls\-tree \-r HEAD:sub dir\fR) in this case, as that would result in asking for
\fBsub/sub/dir\fR
in the
\fBHEAD\fR
commit\&. However, the current working directory can be ignored by passing \-\-full\-tree option\&.
.RE
.SH "OPTIONS"
.PP
<tree\-ish>
.RS 4
Id of a tree\-ish\&.
.RE
.PP
\-d
.RS 4
Show only the named tree entry itself, not its children\&.
.RE
.PP
\-r
.RS 4
Recurse into sub\-trees\&.
.RE
.PP
\-t
.RS 4
Show tree entries even when going to recurse them\&. Has no effect if
\fB\-r\fR
was not passed\&.
\fB\-d\fR
implies
\fB\-t\fR\&.
.RE
.PP
\-l, \-\-long
.RS 4
Show object size of blob (file) entries\&.
.RE
.PP
\-z
.RS 4
\e0 line termination on output and do not quote filenames\&. See OUTPUT FORMAT below for more information\&.
.RE
.PP
\-\-name\-only, \-\-name\-status
.RS 4
List only filenames (instead of the "long" output), one per line\&. Cannot be combined with
\fB\-\-object\-only\fR\&.
.RE
.PP
\-\-object\-only
.RS 4
List only names of the objects, one per line\&. Cannot be combined with
\fB\-\-name\-only\fR
or
\fB\-\-name\-status\fR\&. This is equivalent to specifying
\fB\-\-format=\*(Aq%(objectname)\*(Aq\fR, but for both this option and that exact format the command takes a hand\-optimized codepath instead of going through the generic formatting mechanism\&.
.RE
.PP
\-\-abbrev[=<n>]
.RS 4
Instead of showing the full 40\-byte hexadecimal object lines, show the shortest prefix that is at least
\fI<n>\fR
hexdigits long that uniquely refers the object\&. Non default number of digits can be specified with \-\-abbrev=<n>\&.
.RE
.PP
\-\-full\-name
.RS 4
Instead of showing the path names relative to the current working directory, show the full path names\&.
.RE
.PP
\-\-full\-tree
.RS 4
Do not limit the listing to the current working directory\&. Implies \-\-full\-name\&.
.RE
.PP
\-\-format=<format>
.RS 4
A string that interpolates
\fB%(fieldname)\fR
from the result being shown\&. It also interpolates
\fB%%\fR
to
\fB%\fR, and
\fB%xNN\fR
where
\fBNN\fR
are hex digits interpolates to character with hex code
\fBNN\fR; for example
\fB%x00\fR
interpolates to
\fB\e0\fR
(NUL),
\fB%x09\fR
to
\fB\et\fR
(TAB) and
\fB%x0a\fR
to
\fB\en\fR
(LF)\&. When specified,
\fB\-\-format\fR
cannot be combined with other format\-altering options, including
\fB\-\-long\fR,
\fB\-\-name\-only\fR
and
\fB\-\-object\-only\fR\&.
.RE
.PP
[<path>\&...]
.RS 4
When paths are given, show them (note that this isn\(cqt really raw pathnames, but rather a list of patterns to match)\&. Otherwise implicitly uses the root level of the tree as the sole path argument\&.
.RE
.SH "OUTPUT FORMAT"
.sp
The output format of \fBls\-tree\fR is determined by either the \fB\-\-format\fR option, or other format\-altering options such as \fB\-\-name\-only\fR etc\&. (see \fB\-\-format\fR above)\&.
.sp
The use of certain \fB\-\-format\fR directives is equivalent to using those options, but invoking the full formatting machinery can be slower than using an appropriate formatting option\&.
.sp
In cases where the \fB\-\-format\fR would exactly map to an existing option \fBls\-tree\fR will use the appropriate faster path\&. Thus the default format is equivalent to:
.sp
.if n \{\
.RS 4
.\}
.nf
%(objectmode) %(objecttype) %(objectname)%x09%(path)
.fi
.if n \{\
.RE
.\}
.sp
This output format is compatible with what \fB\-\-index\-info \-\-stdin\fR of \fIgit update\-index\fR expects\&.
.sp
When the \fB\-l\fR option is used, format changes to
.sp
.if n \{\
.RS 4
.\}
.nf
%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)
.fi
.if n \{\
.RE
.\}
.sp
Object size identified by <objectname> is given in bytes, and right\-justified with minimum width of 7 characters\&. Object size is given only for blobs (file) entries; for other entries \fB\-\fR character is used in place of size\&.
.sp
Without the \fB\-z\fR option, pathnames with "unusual" characters are quoted as explained for the configuration variable \fBcore\&.quotePath\fR (see \fBgit-config\fR(1))\&. Using \fB\-z\fR the filename is output verbatim and the line is terminated by a NUL byte\&.
.sp
Customized format:
.sp
It is possible to print in a custom format by using the \fB\-\-format\fR option, which is able to interpolate different fields using a \fB%(fieldname)\fR notation\&. For example, if you only care about the "objectname" and "path" fields, you can execute with a specific "\-\-format" like
.sp
.if n \{\
.RS 4
.\}
.nf
git ls\-tree \-\-format=\*(Aq%(objectname) %(path)\*(Aq <tree\-ish>
.fi
.if n \{\
.RE
.\}
.SH "FIELD NAMES"
.sp
Various values from structured fields can be used to interpolate into the resulting output\&. For each outputting line, the following names can be used:
.PP
objectmode
.RS 4
The mode of the object\&.
.RE
.PP
objecttype
.RS 4
The type of the object (\fBcommit\fR,
\fBblob\fR
or
\fBtree\fR)\&.
.RE
.PP
objectname
.RS 4
The name of the object\&.
.RE
.PP
objectsize[:padded]
.RS 4
The size of a
\fBblob\fR
object ("\-" if it\(cqs a
\fBcommit\fR
or
\fBtree\fR)\&. It also supports a padded format of size with "%(objectsize:padded)"\&.
.RE
.PP
path
.RS 4
The pathname of the object\&.
.RE
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite