1
2
3
4
5
6
7
8
|
<h1>git-ls-tree</h1> <h2 id="_name">Name</h2> <div class="sectionbody"> <p>git-ls-tree - List the contents of a tree object</p> </div> <h2 id="_synopsis">Synopsis</h2> <div class="sectionbody"> <div class="verseblock"> <pre class="content" data-language="shell">git ls-tree [-d] [-r] [-t] [-l] [-z]
[--name-only] [--name-status] [--object-only] [--full-name] [--full-tree] [--abbrev[=<n>]] [--format=<format>]
<tree-ish> [<path>…]</pre> </div> </div> <h2 id="_description">Description</h2> <div class="sectionbody"> <p>Lists the contents of a given tree object, like what "/bin/ls -a" does in the current working directory. Note that:</p> <div class="ulist"> <ul> <li> <p>the behaviour is slightly different from that of "/bin/ls" in that the <code><path></code> denotes just a list of patterns to match, e.g. so specifying directory name (without <code>-r</code>) will behave differently, and order of the arguments does not matter.</p> </li> <li> <p>the behaviour is similar to that of "/bin/ls" in that the <code><path></code> is taken as relative to the current working directory. E.g. when you are in a directory <code>sub</code> that has a directory <code>dir</code>, you can run <code>git ls-tree -r HEAD dir</code> to list the contents of the tree (that is <code>sub/dir</code> in <code>HEAD</code>). You don’t want to give a tree that is not at the root level (e.g. <code>git ls-tree -r HEAD:sub dir</code>) in this case, as that would result in asking for <code>sub/sub/dir</code> in the <code>HEAD</code> commit. However, the current working directory can be ignored by passing --full-tree option.</p> </li> </ul> </div> </div> <h2 id="_options">Options</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-lttree-ishgt"> <tree-ish> </dt> <dd> <p>Id of a tree-ish.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt--d"> -d </dt> <dd> <p>Show only the named tree entry itself, not its children.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt--r"> -r </dt> <dd> <p>Recurse into sub-trees.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt--t"> -t </dt> <dd> <p>Show tree entries even when going to recurse them. Has no effect if <code>-r</code> was not passed. <code>-d</code> implies <code>-t</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt--l"> -l </dt> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---long"> --long </dt> <dd> <p>Show object size of blob (file) entries.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt--z"> -z </dt> <dd> <p>\0 line termination on output and do not quote filenames. See OUTPUT FORMAT below for more information.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---name-only"> --name-only </dt> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---name-status"> --name-status </dt> <dd> <p>List only filenames (instead of the "long" output), one per line. Cannot be combined with <code>--object-only</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---object-only"> --object-only </dt> <dd> <p>List only names of the objects, one per line. Cannot be combined with <code>--name-only</code> or <code>--name-status</code>. This is equivalent to specifying <code>--format='%(objectname)'</code>, but for both this option and that exact format the command takes a hand-optimized codepath instead of going through the generic formatting mechanism.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---abbrevltngt"> --abbrev[=<n>] </dt> <dd> <p>Instead of showing the full 40-byte hexadecimal object lines, show the shortest prefix that is at least <code><n></code> hexdigits long that uniquely refers the object. Non default number of digits can be specified with --abbrev=<n>.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---full-name"> --full-name </dt> <dd> <p>Instead of showing the path names relative to the current working directory, show the full path names.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---full-tree"> --full-tree </dt> <dd> <p>Do not limit the listing to the current working directory. Implies --full-name.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt---formatltformatgt"> --format=<format> </dt> <dd> <p>A string that interpolates <code>%(fieldname)</code> from the result being shown. It also interpolates <code>%%</code> to <code>%</code>, and <code>%xNN</code> where <code>NN</code> are hex digits interpolates to character with hex code <code>NN</code>; for example <code>%x00</code> interpolates to <code>\0</code> (NUL), <code>%x09</code> to <code>\t</code> (TAB) and <code>%x0a</code> to <code>\n</code> (LF). When specified, <code>--format</code> cannot be combined with other format-altering options, including <code>--long</code>, <code>--name-only</code> and <code>--object-only</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-ltpathgt82308203"> [<path>…] </dt> <dd> <p>When paths are given, show them (note that this isn’t 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.</p> </dd> </dl> </div> </div> <h2 id="_output_format">Output format</h2> <div class="sectionbody"> <p>The output format of <code>ls-tree</code> is determined by either the <code>--format</code> option, or other format-altering options such as <code>--name-only</code> etc. (see <code>--format</code> above).</p> <p>The use of certain <code>--format</code> directives is equivalent to using those options, but invoking the full formatting machinery can be slower than using an appropriate formatting option.</p> <p>In cases where the <code>--format</code> would exactly map to an existing option <code>ls-tree</code> will use the appropriate faster path. Thus the default format is equivalent to:</p> <div class="literalblock"> <div class="content"> <pre>%(objectmode) %(objecttype) %(objectname)%x09%(path)</pre> </div> </div> <p>This output format is compatible with what <code>--index-info --stdin</code> of <code>git update-index</code> expects.</p> <p>When the <code>-l</code> option is used, format changes to</p> <div class="literalblock"> <div class="content"> <pre>%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)</pre> </div> </div> <p>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 <code>-</code> character is used in place of size.</p> <p>Without the <code>-z</code> option, pathnames with "unusual" characters are quoted as explained for the configuration variable <code>core.quotePath</code> (see <a href="git-config">git-config[1]</a>). Using <code>-z</code> the filename is output verbatim and the line is terminated by a NUL byte.</p> <p>Customized format:</p> <p>It is possible to print in a custom format by using the <code>--format</code> option, which is able to interpolate different fields using a <code>%(fieldname)</code> notation. For example, if you only care about the "objectname" and "path" fields, you can execute with a specific "--format" like</p> <div class="literalblock"> <div class="content"> <pre data-language="shell">git ls-tree --format='%(objectname) %(path)' <tree-ish></pre> </div> </div> </div> <h2 id="_field_names">Field names</h2> <div class="sectionbody"> <p>Various values from structured fields can be used to interpolate into the resulting output. For each outputting line, the following names can be used:</p> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-objectmode"> objectmode </dt> <dd> <p>The mode of the object.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-objecttype"> objecttype </dt> <dd> <p>The type of the object (<code>commit</code>, <code>blob</code> or <code>tree</code>).</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-objectname"> objectname </dt> <dd> <p>The name of the object.</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-objectsizepadded"> objectsize[:padded] </dt> <dd> <p>The size of a <code>blob</code> object ("-" if it’s a <code>commit</code> or <code>tree</code>). It also supports a padded format of size with "%(objectsize:padded)".</p> </dd> <dt class="hdlist1" id="Documentation/git-ls-tree.txt-path"> path </dt> <dd> <p>The pathname of the object.</p> </dd> </dl> </div> </div><div class="_attribution">
<p class="_attribution-p">
© 2012–2024 Scott Chacon and others<br>Licensed under the MIT License.<br>
<a href="https://git-scm.com/docs/git-ls-tree" class="_attribution-link">https://git-scm.com/docs/git-ls-tree</a>
</p>
</div>
|