{
    "mode": "man",
    "parameter": "git-ls-tree",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/git-ls-tree/1/json",
    "generated": "2026-10-24T20:41:18Z",
    "synopsis": "git ls-tree [-d] [-r] [-t] [-l] [-z]\n[--name-only] [--name-status] [--object-only] [--full-name] [--full-tree] [--abbrev[=<n>]] [--format=<format>]\n<tree-ish> [<path>...]",
    "sections": {
        "NAME": {
            "content": "git-ls-tree - List the contents of a tree object\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git ls-tree [-d] [-r] [-t] [-l] [-z]\n[--name-only] [--name-status] [--object-only] [--full-name] [--full-tree] [--abbrev[=<n>]] [--format=<format>]\n<tree-ish> [<path>...]\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Lists the contents of a given tree object, like what \"/bin/ls -a\" does in the current working\ndirectory. Note that:\n\n•   the behaviour is slightly different from that of \"/bin/ls\" in that the <path> denotes\njust a list of patterns to match, e.g. so specifying directory name (without -r) will\nbehave differently, and order of the arguments does not matter.\n\n•   the behaviour is similar to that of \"/bin/ls\" in that the <path> is taken as relative to\nthe current working directory. E.g. when you are in a directory sub that has a directory\ndir, you can run git ls-tree -r HEAD dir to list the contents of the tree (that is\nsub/dir in HEAD). You don’t want to give a tree that is not at the root level (e.g.  git\nls-tree -r HEAD:sub dir) in this case, as that would result in asking for sub/sub/dir in\nthe HEAD commit. However, the current working directory can be ignored by passing\n--full-tree option.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "<tree-ish>\nId of a tree-ish.\n",
            "subsections": [
                {
                    "name": "-d",
                    "content": "Show only the named tree entry itself, not its children.\n",
                    "flag": "-d"
                },
                {
                    "name": "-r",
                    "content": "Recurse into sub-trees.\n",
                    "flag": "-r"
                },
                {
                    "name": "-t",
                    "content": "Show tree entries even when going to recurse them. Has no effect if -r was not passed.\n-d implies -t.\n",
                    "flag": "-t"
                },
                {
                    "name": "-l, --long",
                    "content": "Show object size of blob (file) entries.\n",
                    "flag": "-l",
                    "long": "--long"
                },
                {
                    "name": "-z",
                    "content": "\\0 line termination on output and do not quote filenames. See OUTPUT FORMAT below for\nmore information.\n",
                    "flag": "-z"
                },
                {
                    "name": "--name-only, --name-status",
                    "content": "List only filenames (instead of the \"long\" output), one per line. Cannot be combined with\n--object-only.\n",
                    "long": "--name-status"
                },
                {
                    "name": "--object-only",
                    "content": "List only names of the objects, one per line. Cannot be combined with --name-only or\n--name-status. This is equivalent to specifying --format='%(objectname)', but for both\nthis option and that exact format the command takes a hand-optimized codepath instead of\ngoing through the generic formatting mechanism.\n\n--abbrev[=<n>]\nInstead of showing the full 40-byte hexadecimal object lines, show the shortest prefix\nthat is at least <n> hexdigits long that uniquely refers the object. Non default number\nof digits can be specified with --abbrev=<n>.\n",
                    "long": "--object-only"
                },
                {
                    "name": "--full-name",
                    "content": "Instead of showing the path names relative to the current working directory, show the\nfull path names.\n",
                    "long": "--full-name"
                },
                {
                    "name": "--full-tree",
                    "content": "Do not limit the listing to the current working directory. Implies --full-name.\n\n--format=<format>\nA string that interpolates %(fieldname) from the result being shown. It also interpolates\n%% to %, and %xNN where NN are hex digits interpolates to character with hex code NN; for\nexample %x00 interpolates to \\0 (NUL), %x09 to \\t (TAB) and %x0a to \\n (LF). When\nspecified, --format cannot be combined with other format-altering options, including\n--long, --name-only and --object-only.\n\n[<path>...]\nWhen paths are given, show them (note that this isn’t really raw pathnames, but rather a\nlist of patterns to match). Otherwise implicitly uses the root level of the tree as the\nsole path argument.\n",
                    "long": "--full-tree"
                }
            ]
        },
        "OUTPUT FORMAT": {
            "content": "The output format of ls-tree is determined by either the --format option, or other\nformat-altering options such as --name-only etc. (see --format above).\n\nThe use of certain --format directives is equivalent to using those options, but invoking the\nfull formatting machinery can be slower than using an appropriate formatting option.\n\nIn cases where the --format would exactly map to an existing option ls-tree will use the\nappropriate faster path. Thus the default format is equivalent to:\n\n%(objectmode) %(objecttype) %(objectname)%x09%(path)\n\nThis output format is compatible with what --index-info --stdin of git update-index expects.\n\nWhen the -l option is used, format changes to\n\n%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)\n\nObject size identified by <objectname> is given in bytes, and right-justified with minimum\nwidth of 7 characters. Object size is given only for blobs (file) entries; for other entries\n- character is used in place of size.\n\nWithout the -z option, pathnames with \"unusual\" characters are quoted as explained for the\nconfiguration variable core.quotePath (see git-config(1)). Using -z the filename is output\nverbatim and the line is terminated by a NUL byte.\n\nCustomized format:\n\nIt is possible to print in a custom format by using the --format option, which is able to\ninterpolate different fields using a %(fieldname) notation. For example, if you only care\nabout the \"objectname\" and \"path\" fields, you can execute with a specific \"--format\" like\n\ngit ls-tree --format='%(objectname) %(path)' <tree-ish>\n",
            "subsections": []
        },
        "FIELD NAMES": {
            "content": "Various values from structured fields can be used to interpolate into the resulting output.\nFor each outputting line, the following names can be used:\n\nobjectmode\nThe mode of the object.\n\nobjecttype\nThe type of the object (commit, blob or tree).\n\nobjectname\nThe name of the object.\n\nobjectsize[:padded]\nThe size of a blob object (\"-\" if it’s a commit or tree). It also supports a padded\nformat of size with \"%(objectsize:padded)\".\n\npath\nThe pathname of the object.\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\nGit 2.43.0                                   07/02/2025                               GIT-LS-TREE(1)",
            "subsections": []
        }
    },
    "summary": "git-ls-tree - List the contents of a tree object",
    "flags": [
        {
            "flag": "-d",
            "long": null,
            "arg": null,
            "description": "Show only the named tree entry itself, not its children."
        },
        {
            "flag": "-r",
            "long": null,
            "arg": null,
            "description": "Recurse into sub-trees."
        },
        {
            "flag": "-t",
            "long": null,
            "arg": null,
            "description": "Show tree entries even when going to recurse them. Has no effect if -r was not passed. -d implies -t."
        },
        {
            "flag": "-l",
            "long": "--long",
            "arg": null,
            "description": "Show object size of blob (file) entries."
        },
        {
            "flag": "-z",
            "long": null,
            "arg": null,
            "description": "\\0 line termination on output and do not quote filenames. See OUTPUT FORMAT below for more information."
        },
        {
            "flag": "",
            "long": "--name-status",
            "arg": null,
            "description": "List only filenames (instead of the \"long\" output), one per line. Cannot be combined with --object-only."
        },
        {
            "flag": "",
            "long": "--object-only",
            "arg": null,
            "description": "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>."
        },
        {
            "flag": "",
            "long": "--full-name",
            "arg": null,
            "description": "Instead of showing the path names relative to the current working directory, show the full path names."
        },
        {
            "flag": "",
            "long": "--full-tree",
            "arg": null,
            "description": "Do not limit the listing to the current working directory. Implies --full-name. --format=<format> A string that interpolates %(fieldname) from the result being shown. It also interpolates %% to %, and %xNN where NN are hex digits interpolates to character with hex code NN; 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. [<path>...] 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."
        }
    ],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "List the contents of a tree object.",
        "examples": [
            {
                "description": "List the contents of the tree on a branch",
                "command": "git ls-tree {{branch_name}}"
            },
            {
                "description": "List the contents of the tree on a commit, recursing into subtrees",
                "command": "git ls-tree -r {{commit_hash}}"
            },
            {
                "description": "List only the filenames of the tree on a commit",
                "command": "git ls-tree --name-only {{commit_hash}}"
            },
            {
                "description": "Print the filenames of the current branch head in a tree structure (Note: `tree --fromfile` is not supported on Windows)",
                "command": "git ls-tree -r --name-only HEAD | tree --fromfile"
            }
        ]
    }
}