ls(1) for git trees.
List entries in a tree object: paths, modes, types, and SHAs. Think ls(1) for git's content-addressable tree, not the working directory.
A tree is a flat directory listing pointing at blobs and other trees. ls-tree reads one tree-ish and prints its entries; -r flattens it like a recursive ls -R against history rather than disk.
git ls-tree [-d] [-r] [-t] [-l] [-z]
[--name-only] [--object-only] [--full-name] [--full-tree]
[--abbrev[=<n>]]
<tree-ish> [<path>...]| Flag | What it does |
|---|---|
<tree-ish> | Commit, tag, branch, or raw tree SHA to read. |
-r | Recurse into sub-trees (flatten the listing). |
-d | Show only directory (tree) entries. |
-t | Show tree entries even when recursing with -r. |
-l, --long | Add blob size as a fifth column (- for trees). |
--name-only | Print just the path; useful for piping. |
--object-only | Print just the SHA; pair with xargs cat-file. |
--abbrev=<n> | Abbreviate SHAs to <n> hex chars. |
--full-name | Print paths from the repo root, not the cwd. |
--full-tree | Behave as if run from the repo root (path args become absolute-in-repo). |
-z | NUL-terminate paths; safe for filenames with newlines. |
cat-file to grep historical content.-l).git ls-tree HEADgit ls-tree -r v1.2.0git ls-tree -lr HEAD -- src/git ls-tree -r -z --name-only HEADls-tree when you need committed state; ls-files is for the index, plain ls is for the working tree.--full-tree in scripts so behaviour does not depend on the cwd inside the repo.-r you only see the top of the tree; nested files are hidden behind tree entries.--full-tree is on; without it, paths are relative to cwd.Hit each option, then Check answers. Score is recorded; Next is always open.