LinuxCommandLibrary

git-ls-tree

List tree object contents

TLDR

List tree contents

$ git ls-tree HEAD
copy
List recursively
$ git ls-tree -r HEAD
copy
Show only names
$ git ls-tree --name-only HEAD
copy
List specific directory
$ git ls-tree HEAD [src/]
copy
Show sizes
$ git ls-tree -l HEAD
copy

SYNOPSIS

git ls-tree [options] tree-ish [path]

DESCRIPTION

git ls-tree lists the contents of a tree object, showing file names, modes, types, and object hashes for a specific commit's directory structure. It provides a snapshot of the repository's file layout at any given commit.
The command is useful for scripting and understanding how Git stores directory contents internally. Recursive mode (`-r`) shows all files across all subdirectories, while `--name-only` provides clean output suitable for piping to other commands.

PARAMETERS

TREE-ISH

Tree or commit to list.
PATH
Limit to path.
-r
Recurse into subtrees.
-d
Show only trees.
--name-only
Show only names.
--name-status
Show names and status.
-l, --long
Show object sizes.
--abbrev N
Abbreviate hashes.
--help
Display help information.

CAVEATS

Shows tree at specific commit. Plumbing command for scripts. Output format is machine-readable.

HISTORY

git ls-tree is a core Git plumbing command for examining tree objects, part of git's low-level interface.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community