LinuxCommandLibrary

git-ls-files

List files tracked by Git

TLDR

Show deleted files

$ git ls-files [[-d|--deleted]]
copy

Show modified and deleted files
$ git ls-files [[-m|--modified]]
copy

Show ignored and untracked files
$ git ls-files [[-o|--others]]
copy

Show untracked files, not ignored
$ git ls-files [[-o|--others]] --exclude-standard
copy

SYNOPSIS

git ls-files [-z] [-t] [-v] [-c] [-d] [-m] [-k] [-o] [-i] [-s] [-u] [--stage] [--unmerged] [--exclude-standard] [--full-name] [--empty-directory] [--eol] [--resolve-undo] [-x <pattern>] [-X <file>] [--exclude-per-directory=<file>] [--exclude-from=<file>] [--exclude=<pattern>] [--error-unmatch] [--with-tree=<tree-ish>] [--index-info] [--only-unmerged] [-q] [--] [<file>...]

PARAMETERS

-z
    Terminate entries with NUL, instead of newline.

-t
    Identify the file type.

-v
    Be verbose, showing mode bits, object name and stage number.

-c
    Show cached files.

-d
    Show deleted files.

-m
    Show modified files.

-k
    Show files on the filesystem, but are marked as to be killed.

-o
    Show other (i.e. untracked) files.

-i
    Show ignored files.

-s
    Show staged contents' object name, mode bits and stage number.

-u
    Show unmerged files.

--stage
    Show staged contents' object name, mode bits and stage number.

--unmerged
    Show unmerged files.

--exclude-standard
    Add the standard Git exclusions.

--full-name
    Make the output relative to the project top directory.

--empty-directory
    Show empty directories.

--eol
    Show eolinfo attributes of files.

--resolve-undo
    Show resolve-undo information.

-x <pattern>
    Exclude files matching pattern.

-X <file>
    Exclude files matching patterns read from <file>.

--exclude-per-directory=<file>
    Read additional exclude patterns from <file> in each directory.

--exclude-from=<file>
    Read exclude patterns from <file>.

--exclude=<pattern>
    Exclude files matching pattern.

--error-unmatch
    If any <file> doesn't match anything, show an error.

--with-tree=<tree-ish>
    Pretend that the tree object <tree-ish> is the HEAD.

--index-info
    Read index information from stdin.

--only-unmerged
    Only show things that are unmerged.

-q
    Quiet mode.

[<file>...]
    List only these files.

DESCRIPTION

The git ls-files command provides various ways to list the files tracked by Git. It interacts directly with the Git index (staging area) to retrieve this information. It can list files that are tracked, untracked, ignored, or staged for commit. It's often used for scripting or in conjunction with other Git commands. Different options can refine the output to show only certain types of files (e.g., staged, modified, deleted) and to format the output in specific ways. Unlike commands that operate on the working directory (like `ls`), `git ls-files` reports on what Git _knows_ about the state of your project.

Common use cases include verifying which files are tracked, debugging staging issues, and automating file-related tasks within a Git repository.

EXIT STATUS

The command exits with success if all files were found, even when --error-unmatch is used. If any file could not be found the command exits with non-zero status.

SEE ALSO

Copied to clipboard