Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
Guides
- gitattributes
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- Glossary
- Hooks
- gitignore
- gitmodules
- Revisions
- Submodules
- Tutorial
- Workflows
- All guides...
Administration
Plumbing Commands
- 2.42.1 → 2.44.0 no changes
- 2.42.0 08/21/23
- 2.36.1 → 2.41.0 no changes
- 2.36.0 04/18/22
- 2.30.1 → 2.35.8 no changes
- 2.30.0 12/27/20
概述
git ls-tree [-d] [-r] [-t] [-l] [-z] [--name-only] [--name-status] [--object-only] [--full-name] [--full-tree] [--abbrev[=<n>]] [--format=<格式>] <目录树对象> [<路径>…]
描述
Lists the contents of a given tree object, like what "/bin/ls -a" does in the current working directory. Note that:
-
行为与 "/bin/ls" 略有不同,<路径> 表示的只是要匹配的模式列表,例如,指定目录名(不含
-r
)的行为会有所不同,参数的顺序并不重要。 -
the behaviour is similar to that of "/bin/ls" in that the <path> is taken as relative to the current working directory. E.g. when you are in a directory sub that has a directory dir, you can run git ls-tree -r HEAD dir to list the contents of the tree (that is
sub/dir
inHEAD
). You don’t want to give a tree that is not at the root level (e.g.git ls-tree -r HEAD:sub dir
) in this case, as that would result in asking forsub/sub/dir
in theHEAD
commit. However, the current working directory can be ignored by passing --full-tree option.
选项
- <tree-ish>
-
树状对象 ID。
- -d
-
只显示已命名的目录条目本身,不显示其子条目。
- -r
-
向子树递归。
- -t
-
即使在递归时也显示树条目。如果未传递
-r
,则无影响。-d
意味着-t
。 - -l
- --long
-
显示 blob(文件)条目的对象大小。
- -z
-
\0 line termination on output and do not quote filenames. See OUTPUT FORMAT below for more information.
- --name-only
- --name-status
-
List only filenames (instead of the "long" output), one per line. Cannot be combined with
--object-only
. - --object-only
-
List only names of the objects, one per line. Cannot be combined with
--name-only
or--name-status
. This is equivalent to specifying--format='%(objectname)'
, but for both this option and that exact format the command takes a hand-optimized codepath instead of going through the generic formatting mechanism. - --abbrev[=<n>]
-
Instead of showing the full 40-byte hexadecimal object lines, show the shortest prefix that is at least <n> hexdigits long that uniquely refers the object. Non default number of digits can be specified with --abbrev=<n>.
- --full-name
-
不显示相对于当前工作目录的路径名,而是显示完整的路径名。
- --full-tree
-
Do not limit the listing to the current working directory. Implies --full-name.
- --format=<格式>
-
A string that interpolates
%(fieldname)
from the result being shown. It also interpolates%%
to%
, and%xNN
whereNN
are hex digits interpolates to character with hex codeNN
; for example%x00
interpolates to\0
(NUL),%x09
to\t
(TAB) and%x0a
to\n
(LF). When specified,--format
cannot be combined with other format-altering options, including--long
,--name-only
and--object-only
. - [<路径>…]
-
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.
输出格式
The output format of ls-tree
is determined by either the --format
option, or other format-altering options such as --name-only
etc. (see --format
above).
使用某些 --format
指令等同于使用这些选项,但调用完整的格式化机制可能比使用适当的格式化选项要慢。
在 --format
与现有选项完全对应的情况下,ls-tree
将使用适当的更快路径。因此,默认格式相当于:
%(对象模式) %(对象类型) %(对象名)%x09%(路径)
该输出格式与 git update-index 的 --index-info--stdin
所期望的格式兼容。
当使用 -l
选项时,格式变为
%(对象模式) %(对象类型) %(对象名) %(对象大小:padded)%x09%(路径)
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 -
character is used in place of size.
Without the -z
option, pathnames with "unusual" characters are quoted as explained for the configuration variable core.quotePath
(see git-config[1]). Using -z
the filename is output verbatim and the line is terminated by a NUL byte.
定制格式:
使用 "--format" 选项可以自定义打印格式,该选项可以使用 %(fieldname)
符号对不同字段进行插值。例如,如果只关心 “对象名” 和 “路径” 字段,可以使用特定的 "--format" 执行,如
git ls-tree --format='%(对象名) %(路径)' <树状对象>
GIT
属于 git[1] 文档