NAME

git-ls-files - Show information about files in the index and the working tree

SYNOPSIS

  1. git ls-files [-z] [-t] [-v] [-f]
  2. (--[cached|deleted|others|ignored|stage|unmerged|killed|modified])*
  3. (-[c|d|o|i|s|u|k|m])*
  4. [--eol]
  5. [-x <pattern>|--exclude=<pattern>]
  6. [-X <file>|--exclude-from=<file>]
  7. [--exclude-per-directory=<file>]
  8. [--exclude-standard]
  9. [--error-unmatch] [--with-tree=<tree-ish>]
  10. [--full-name] [--recurse-submodules]
  11. [--abbrev] [--] [<file>…​]

DESCRIPTION

This merges the file listing in the directory cache index with theactual working directory list, and shows different combinations of thetwo.

One or more of the options below may be used to determine the filesshown:

OPTIONS

  • -c
  • —cached
  • Show cached files in the output (default)

  • -d

  • —deleted
  • Show deleted files in the output

  • -m

  • —modified
  • Show modified files in the output

  • -o

  • —others
  • Show other (i.e. untracked) files in the output

  • -i

  • —ignored
  • Show only ignored files in the output. When showing files in theindex, print only those matched by an exclude pattern. Whenshowing "other" files, show only those matched by an excludepattern. Standard ignore rules are not automatically activated,therefore at least one of the —exclude* options is required.

  • -s

  • —stage
  • Show staged contents' mode bits, object name and stage number in the output.

  • —directory

  • If a whole directory is classified as "other", show just itsname (with a trailing slash) and not its whole contents.

  • —no-empty-directory

  • Do not list empty directories. Has no effect without —directory.

  • -u

  • —unmerged
  • Show unmerged files in the output (forces —stage)

  • -k

  • —killed
  • Show files on the filesystem that need to be removed dueto file/directory conflicts for checkout-index tosucceed.

  • -z

  • \0 line termination on output and do not quote filenames.See OUTPUT below for more information.

  • -x

  • —exclude=
  • Skip untracked files matching pattern.Note that pattern is a shell wildcard pattern. See EXCLUDE PATTERNSbelow for more information.

  • -X

  • —exclude-from=
  • Read exclude patterns from ; 1 per line.

  • —exclude-per-directory=

  • Read additional exclude patterns that apply only to thedirectory and its subdirectories in .

  • —exclude-standard

  • Add the standard Git exclusions: .git/info/exclude, .gitignorein each directory, and the user’s global exclusion file.

  • —error-unmatch

  • If any does not appear in the index, treat this as anerror (return 1).

  • —with-tree=

  • When using —error-unmatch to expand the user supplied (i.e. path pattern) arguments to paths, pretendthat paths which were removed in the index since thenamed are still present. Using this optionwith -s or -u options does not make any sense.

  • -t

  • This feature is semi-deprecated. For scripting purpose,git-status[1] —porcelain andgit-diff-files[1] —name-status are almost alwayssuperior alternatives, and users should look atgit-status[1] —short or git-diff[1]—name-status for more user-friendly alternatives.

This option identifies the file status with the following tags (followed bya space) at the start of each line:

  • H
  • cached

  • S

  • skip-worktree

  • M

  • unmerged

  • R

  • removed/deleted

  • C

  • modified/changed

  • K

  • to be killed

  • ?

  • other
  • -v
  • Similar to -t, but use lowercase letters for filesthat are marked as assume unchanged (seegit-update-index[1]).

  • -f

  • Similar to -t, but use lowercase letters for filesthat are marked as fsmonitor valid (seegit-update-index[1]).

  • —full-name

  • When run from a subdirectory, the command usuallyoutputs paths relative to the current directory. Thisoption forces paths to be output relative to the projecttop directory.

  • —recurse-submodules

  • Recursively calls ls-files on each submodule in the repository.Currently there is only support for the —cached mode.

  • —abbrev[=]

  • Instead of showing the full 40-byte hexadecimal objectlines, show only a partial prefix.Non default number of digits can be specified with —abbrev=.

  • —debug

  • After each line that describes a file, add more data about itscache entry. This is intended to show as much information aspossible for manual inspection; the exact format may change atany time.

  • —eol

  • Show and of files. is the file content identification used by Git whenthe "text" attribute is "auto" (or not set and core.autocrlf is not false). is either "-text", "none", "lf", "crlf", "mixed" or "".

"" means the file is not a regular file, it is not in the index ornot accessible in the working tree.

is the attribute that is used when checking out or committing,it is either "", "-text", "text", "text=auto", "text eol=lf", "text eol=crlf".Since Git 2.10 "text=auto eol=lf" and "text=auto eol=crlf" are supported.

Both the in the index ("i/")and in the working tree ("w/") are shown for regular files,followed by the ("attr/").

  • Do not interpret any more arguments as options.

  • Files to show. If no files are given all files which match the otherspecified criteria are shown.

OUTPUT

git ls-files just outputs the filenames unless —stage is specified inwhich case it outputs:

  1. [<tag> ]<mode> <object> <stage> <file>

git ls-files —eol will showi/<eolinfo><SPACES>w/<eolinfo><SPACES>attr/<eolattr><SPACE*><TAB><file>

git ls-files —unmerged and git ls-files —stage can be used to examinedetailed information on unmerged paths.

For an unmerged path, instead of recording a single mode/SHA-1 pair,the index records up to three such pairs; one from tree O in stage1, A in stage 2, and B in stage 3. This information can be used bythe user (or the porcelain) to see what should eventually be recorded at thepath. (see git-read-tree[1] for more information on state)

Without the -z option, pathnames with "unusual" characters arequoted as explained for the configuration variable core.quotePath(see git-config[1]). Using -z the filename is outputverbatim and the line is terminated by a NUL byte.

EXCLUDE PATTERNS

git ls-files can use a list of "exclude patterns" whentraversing the directory tree and finding files to show when theflags —others or —ignored are specified. gitignore[5]specifies the format of exclude patterns.

These exclude patterns come from these places, in order:

  • The command-line flag —exclude= specifies asingle pattern. Patterns are ordered in the same orderthey appear in the command line.

  • The command-line flag —exclude-from= specifies afile containing a list of patterns. Patterns are orderedin the same order they appear in the file.

  • The command-line flag —exclude-per-directory= specifiesa name of the file in each directory _git ls-files_examines, normally .gitignore. Files in deeperdirectories take precedence. Patterns are ordered in thesame order they appear in the files.

A pattern specified on the command line with —exclude or readfrom the file specified with —exclude-from is relative to thetop of the directory tree. A pattern read from a file specifiedby —exclude-per-directory is relative to the directory that thepattern file appears in.

SEE ALSO

git-read-tree[1], gitignore[5]

GIT

Part of the git[1] suite