Linux command
git-ls-tree 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
List tree contents
git ls-tree HEAD
List recursively
git ls-tree -r HEAD
Show only names
git ls-tree --name-only HEAD
List specific directory
git ls-tree HEAD [src/]
Show sizes
git ls-tree -l HEAD
说明
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.
参数
- -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.
FAQ
What is the git-ls-tree command used for?
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.
How do I run a basic git-ls-tree example?
Run `git ls-tree HEAD` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -r do in git-ls-tree?
Recurse into subtrees.