Progress:
TIER 3 · MODULE 33· Expert

git ls-tree

ls(1) for git trees.

🎯 What & why

List entries in a tree object: paths, modes, types, and SHAs. Think ls(1) for git's content-addressable tree, not the working directory.

🧠 Mental model

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.

🛠️ Synopsis

git ls-tree [-d] [-r] [-t] [-l] [-z]
            [--name-only] [--object-only] [--full-name] [--full-tree]
            [--abbrev[=<n>]]
            <tree-ish> [<path>...]

🎚️ Switches & options

FlagWhat it does
<tree-ish>Commit, tag, branch, or raw tree SHA to read.
-rRecurse into sub-trees (flatten the listing).
-dShow only directory (tree) entries.
-tShow tree entries even when recursing with -r.
-l, --longAdd blob size as a fifth column (- for trees).
--name-onlyPrint just the path; useful for piping.
--object-onlyPrint just the SHA; pair with xargs cat-file.
--abbrev=<n>Abbreviate SHAs to <n> hex chars.
--full-namePrint paths from the repo root, not the cwd.
--full-treeBehave as if run from the repo root (path args become absolute-in-repo).
-zNUL-terminate paths; safe for filenames with newlines.

💡 Use cases

🧪 Examples

Top-level entries of HEAD
git ls-tree HEAD
All files at a tag, recursive
git ls-tree -r v1.2.0
Sizes for blobs in a subdir
git ls-tree -lr HEAD -- src/
Just the paths, NUL-safe
git ls-tree -r -z --name-only HEAD

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.