<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="git-ls-files(1)">
    <title>git-ls-files(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>git-ls-files(1)</primary>
</indexterm>
<simplesect id="git-ls-files(1)__name">
<title>NAME</title>
<simpara>git-ls-files - Show information about files in the index and the working tree</simpara>
</simplesect>
<simplesect id="git-ls-files(1)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git ls-files</emphasis> [-z] [-t] [-v] [-f]
                [-c|--cached] [-d|--deleted] [-o|--others] [-i|--ignored]
                [-s|--stage] [-u|--unmerged] [-k|--killed] [-m|--modified]
                [--resolve-undo]
                [--directory [--no-empty-directory]] [--eol]
                [--deduplicate]
                [-x &lt;pattern&gt;|--exclude=&lt;pattern&gt;]
                [-X &lt;file&gt;|--exclude-from=&lt;file&gt;]
                [--exclude-per-directory=&lt;file&gt;]
                [--exclude-standard]
                [--error-unmatch] [--with-tree=&lt;tree-ish&gt;]
                [--full-name] [--recurse-submodules]
                [--abbrev[=&lt;n&gt;]] [--format=&lt;format&gt;] [--] [&lt;file&gt;&#8230;]</literallayout>
</blockquote>
</simplesect>
<simplesect id="git-ls-files(1)__description">
<title>DESCRIPTION</title>
<simpara>This command merges the file listing in the index with the actual working
directory list, and shows different combinations of the two.</simpara>
<simpara>Several flags can be used to determine which files are
shown, and each file may be printed multiple times if there are
multiple entries in the index or if multiple statuses are applicable for
the relevant file selection options.</simpara>
</simplesect>
<simplesect id="git-ls-files(1)__options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
-c
</term>
<term>
--cached
</term>
<listitem>
<simpara>
        Show all files cached in Git's index, i.e. all tracked files.
        (This is the default if no -c/-s/-d/-o/-u/-k/-m/--resolve-undo
        options are specified.)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-d
</term>
<term>
--deleted
</term>
<listitem>
<simpara>
        Show files with an unstaged deletion
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-m
</term>
<term>
--modified
</term>
<listitem>
<simpara>
        Show files with an unstaged modification (note that an unstaged
        deletion also counts as an unstaged modification)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-o
</term>
<term>
--others
</term>
<listitem>
<simpara>
        Show other (i.e. untracked) files in the output
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-i
</term>
<term>
--ignored
</term>
<listitem>
<simpara>
        Show only ignored files in the output.  Must be used with
        either an explicit <emphasis>-c</emphasis> or <emphasis>-o</emphasis>.  When showing files in the
        index (i.e. when used with <emphasis>-c</emphasis>), print only those files
        matching an exclude pattern.  When showing "other" files
        (i.e. when used with <emphasis>-o</emphasis>), show only those matched by an
        exclude pattern.  Standard ignore rules are not automatically
        activated; therefore, at least one of the <emphasis>--exclude*</emphasis> options
        is required.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-s
</term>
<term>
--stage
</term>
<listitem>
<simpara>
        Show staged contents' mode bits, object name and stage number in the output.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--directory
</term>
<listitem>
<simpara>
        If a whole directory is classified as "other", show just its
        name (with a trailing slash) and not its whole contents.
        Has no effect without -o/--others.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-empty-directory
</term>
<listitem>
<simpara>
        Do not list empty directories. Has no effect without --directory.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-u
</term>
<term>
--unmerged
</term>
<listitem>
<simpara>
        Show information about unmerged files in the output, but do
        not show any other tracked files (forces --stage, overrides
        --cached).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-k
</term>
<term>
--killed
</term>
<listitem>
<simpara>
        Show untracked files on the filesystem that need to be removed
        due to file/directory conflicts for tracked files to be able to
        be written to the filesystem.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--resolve-undo
</term>
<listitem>
<simpara>
        Show files having resolve-undo information in the index
        together with their resolve-undo information.  (resolve-undo
        information is what is used to implement "git checkout -m
        $PATH", i.e. to recreate merge conflicts that were
        accidentally resolved)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-z
</term>
<listitem>
<simpara>
        \0 line termination on output and do not quote filenames.
        See OUTPUT below for more information.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--deduplicate
</term>
<listitem>
<simpara>
        When only filenames are shown, suppress duplicates that may
        come from having multiple stages during a merge, or giving
        <emphasis>--deleted</emphasis> and <emphasis>--modified</emphasis> option at the same time.
        When any of the <emphasis>-t</emphasis>, <emphasis>--unmerged</emphasis>, or <emphasis>--stage</emphasis> option is
        in use, this option has no effect.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-x &lt;pattern&gt;
</term>
<term>
--exclude=&lt;pattern&gt;
</term>
<listitem>
<simpara>
        Skip untracked files matching pattern.
        Note that pattern is a shell wildcard pattern. See EXCLUDE PATTERNS
        below for more information.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-X &lt;file&gt;
</term>
<term>
--exclude-from=&lt;file&gt;
</term>
<listitem>
<simpara>
        Read exclude patterns from &lt;file&gt;; 1 per line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--exclude-per-directory=&lt;file&gt;
</term>
<listitem>
<simpara>
        Read additional exclude patterns that apply only to the
        directory and its subdirectories in &lt;file&gt;.  If you are
        trying to emulate the way Porcelain commands work, using
        the <emphasis>--exclude-standard</emphasis> option instead is easier and more
        thorough.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--exclude-standard
</term>
<listitem>
<simpara>
        Add the standard Git exclusions: .git/info/exclude, .gitignore
        in each directory, and the user's global exclusion file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--error-unmatch
</term>
<listitem>
<simpara>
        If any &lt;file&gt; does not appear in the index, treat this as an
        error (return 1).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--with-tree=&lt;tree-ish&gt;
</term>
<listitem>
<simpara>
        When using --error-unmatch to expand the user supplied
        &lt;file&gt; (i.e. path pattern) arguments to paths, pretend
        that paths which were removed in the index since the
        named &lt;tree-ish&gt; are still present.  Using this option
        with <emphasis>-s</emphasis> or <emphasis>-u</emphasis> options does not make any sense.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-t
</term>
<listitem>
<simpara>
        Show status tags together with filenames.  Note that for
        scripting purposes, <xref linkend="git-status(1)" /> <emphasis>--porcelain</emphasis> and
        <xref linkend="git-diff-files(1)" /> <emphasis>--name-status</emphasis> are almost always
        superior alternatives; users should look at
        <xref linkend="git-status(1)" /> <emphasis>--short</emphasis> or <xref linkend="git-diff(1)" />
        <emphasis>--name-status</emphasis> for more user-friendly alternatives.
</simpara>
<simpara>This option provides a reason for showing each filename, in the form
of a status tag (which is followed by a space and then the filename).
The status tags are all single characters from the following list:</simpara>
<variablelist>
<varlistentry>
<term>
H
</term>
<listitem>
<simpara>
tracked file that is not either unmerged or skip-worktree
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
S
</term>
<listitem>
<simpara>
tracked file that is skip-worktree
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
M
</term>
<listitem>
<simpara>
tracked file that is unmerged
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
R
</term>
<listitem>
<simpara>
tracked file with unstaged removal/deletion
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
C
</term>
<listitem>
<simpara>
tracked file with unstaged modification/change
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
K
</term>
<listitem>
<simpara>
untracked paths which are part of file/directory conflicts
                which prevent checking out tracked files
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
?
</term>
<listitem>
<simpara>
untracked file
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
U
</term>
<listitem>
<simpara>
file with resolve-undo information
</simpara>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
<varlistentry>
<term>
-v
</term>
<listitem>
<simpara>
        Similar to <emphasis>-t</emphasis>, but use lowercase letters for files
        that are marked as <emphasis>assume unchanged</emphasis> (see
        <xref linkend="git-update-index(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-f
</term>
<listitem>
<simpara>
        Similar to <emphasis>-t</emphasis>, but use lowercase letters for files
        that are marked as <emphasis>fsmonitor valid</emphasis> (see
        <xref linkend="git-update-index(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--full-name
</term>
<listitem>
<simpara>
        When run from a subdirectory, the command usually
        outputs paths relative to the current directory.  This
        option forces paths to be output relative to the project
        top directory.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--recurse-submodules
</term>
<listitem>
<simpara>
        Recursively calls ls-files on each active submodule in the repository.
        Currently there is only support for the --cached and --stage modes.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--abbrev[=&lt;n&gt;]
</term>
<listitem>
<simpara>
        Instead of showing the full 40-byte hexadecimal object
        lines, show the shortest prefix that is at least <emphasis>&lt;n&gt;</emphasis>
        hexdigits long that uniquely refers the object.
        Non default number of digits can be specified with --abbrev=&lt;n&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--debug
</term>
<listitem>
<simpara>
        After each line that describes a file, add more data about its
        cache entry.  This is intended to show as much information as
        possible for manual inspection; the exact format may change at
        any time.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--eol
</term>
<listitem>
<simpara>
        Show &lt;eolinfo&gt; and &lt;eolattr&gt; of files.
        &lt;eolinfo&gt; is the file content identification used by Git when
        the "text" attribute is "auto" (or not set and core.autocrlf is not false).
        &lt;eolinfo&gt; is either "-text", "none", "lf", "crlf", "mixed" or "".
</simpara>
<simpara>"" means the file is not a regular file, it is not in the index or
not accessible in the working tree.</simpara>
<simpara>&lt;eolattr&gt; 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.</simpara>
<simpara>Both the &lt;eolinfo&gt; in the index ("i/&lt;eolinfo&gt;")
and in the working tree ("w/&lt;eolinfo&gt;") are shown for regular files,
followed by the  ("attr/&lt;eolattr&gt;").</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--sparse
</term>
<listitem>
<simpara>
        If the index is sparse, show the sparse directories without expanding
        to the contained files. Sparse directories will be shown with a
        trailing slash, such as "x/" for a sparse directory "x".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--format=&lt;format&gt;
</term>
<listitem>
<simpara>
        A string that interpolates <emphasis>%(fieldname)</emphasis> from the result being shown.
        It also interpolates <emphasis>%%</emphasis> to <emphasis>%</emphasis>, and <emphasis>%xx</emphasis> where <emphasis>xx</emphasis> are hex digits
        interpolates to character with hex code <emphasis>xx</emphasis>; for example <emphasis>%00</emphasis>
        interpolates to <emphasis>\0</emphasis> (NUL), <emphasis>%09</emphasis> to <emphasis>\t</emphasis> (TAB) and %0a to <emphasis>\n</emphasis> (LF).
        --format cannot be combined with <emphasis>-s</emphasis>, <emphasis>-o</emphasis>, <emphasis>-k</emphasis>, <emphasis>-t</emphasis>, <emphasis>--resolve-undo</emphasis>
        and <emphasis>--eol</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--
</term>
<listitem>
<simpara>
        Do not interpret any more arguments as options.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;file&gt;
</term>
<listitem>
<simpara>
        Files to show. If no files are given all files which match the other
        specified criteria are shown.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-ls-files(1)__output">
<title>OUTPUT</title>
<simpara><emphasis>git ls-files</emphasis> just outputs the filenames unless <emphasis>--stage</emphasis> is specified in
which case it outputs:</simpara>
<literallayout class="monospaced">[&lt;tag&gt; ]&lt;mode&gt; &lt;object&gt; &lt;stage&gt; &lt;file&gt;</literallayout>
<simpara><emphasis>git ls-files --eol</emphasis> will show
        i/&lt;eolinfo&gt;&lt;SPACES&gt;w/&lt;eolinfo&gt;&lt;SPACES&gt;attr/&lt;eolattr&gt;&lt;SPACE*&gt;&lt;TAB&gt;&lt;file&gt;</simpara>
<simpara><emphasis>git ls-files --unmerged</emphasis> and <emphasis>git ls-files --stage</emphasis> can be used to examine
detailed information on unmerged paths.</simpara>
<simpara>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 stage
1, A in stage 2, and B in stage 3.  This information can be used by
the user (or the porcelain) to see what should eventually be recorded at the
path. (see <xref linkend="git-read-tree(1)" /> for more information on state)</simpara>
<simpara>Without the <emphasis>-z</emphasis> option, pathnames with "unusual" characters are
quoted as explained for the configuration variable <emphasis>core.quotePath</emphasis>
(see <xref linkend="git-config(1)" />).  Using <emphasis>-z</emphasis> the filename is output
verbatim and the line is terminated by a NUL byte.</simpara>
<simpara>It is possible to print in a custom format by using the <emphasis>--format</emphasis>
option, which is able to interpolate different fields using
a <emphasis>%(fieldname)</emphasis> notation. For example, if you only care about the
"objectname" and "path" fields, you can execute with a specific
"--format" like</simpara>
<literallayout class="monospaced">git ls-files --format='%(objectname) %(path)'</literallayout>
</simplesect>
<simplesect id="git-ls-files(1)__field_names">
<title>FIELD NAMES</title>
<simpara>The way each path is shown can be customized by using the
<emphasis>--format=&lt;format&gt;</emphasis> option, where the %(fieldname) in the
&lt;format&gt; string for various aspects of the index entry are
interpolated.  The following "fieldname" are understood:</simpara>
<variablelist>
<varlistentry>
<term>
objectmode
</term>
<listitem>
<simpara>
        The mode of the file which is recorded in the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
objecttype
</term>
<listitem>
<simpara>
        The object type of the file which is recorded in the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
objectname
</term>
<listitem>
<simpara>
        The name of the file which is recorded in the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
objectsize[:padded]
</term>
<listitem>
<simpara>
        The object size of the file which is recorded in the index
        ("-" if the object is a <emphasis>commit</emphasis> or <emphasis>tree</emphasis>).
        It also supports a padded format of size with "%(objectsize:padded)".
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
stage
</term>
<listitem>
<simpara>
        The stage of the file which is recorded in the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
eolinfo:index
</term>
<term>
eolinfo:worktree
</term>
<listitem>
<simpara>
        The &lt;eolinfo&gt; (see the description of the <emphasis>--eol</emphasis> option) of
        the contents in the index or in the worktree for the path.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
eolattr
</term>
<listitem>
<simpara>
        The &lt;eolattr&gt; (see the description of the <emphasis>--eol</emphasis> option)
        that applies to the path.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
path
</term>
<listitem>
<simpara>
        The pathname of the file which is recorded in the index.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-ls-files(1)__exclude_patterns">
<title>EXCLUDE PATTERNS</title>
<simpara><emphasis>git ls-files</emphasis> can use a list of "exclude patterns" when
traversing the directory tree and finding files to show when the
flags --others or --ignored are specified.  <xref linkend="gitignore(5)" />
specifies the format of exclude patterns.</simpara>
<simpara>These exclude patterns can be specified from the following places,
in order:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
The command-line flag --exclude=&lt;pattern&gt; specifies a
     single pattern.  Patterns are ordered in the same order
     they appear in the command line.
</simpara>
</listitem>
<listitem>
<simpara>
The command-line flag --exclude-from=&lt;file&gt; specifies a
     file containing a list of patterns.  Patterns are ordered
     in the same order they appear in the file.
</simpara>
</listitem>
<listitem>
<simpara>
The command-line flag --exclude-per-directory=&lt;name&gt; specifies
     a name of the file in each directory <emphasis>git ls-files</emphasis>
     examines, normally <emphasis>.gitignore</emphasis>.  Files in deeper
     directories take precedence.  Patterns are ordered in the
     same order they appear in the files.
</simpara>
</listitem>
</orderedlist>
<simpara>A pattern specified on the command line with --exclude or read
from the file specified with --exclude-from is relative to the
top of the directory tree.  A pattern read from a file specified
by --exclude-per-directory is relative to the directory that the
pattern file appears in.</simpara>
<simpara>Generally, you should be able to use <emphasis>--exclude-standard</emphasis> when you
want the exclude rules applied the same way as what Porcelain
commands do.  To emulate what <emphasis>--exclude-standard</emphasis> specifies, you
can give <emphasis>--exclude-per-directory=.gitignore</emphasis>, and then specify:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
The file specified by the <emphasis>core.excludesfile</emphasis> configuration
     variable, if exists, or the <emphasis>$XDG_CONFIG_HOME/git/ignore</emphasis> file.
</simpara>
</listitem>
<listitem>
<simpara>
The <emphasis>$GIT_DIR/info/exclude</emphasis> file.
</simpara>
</listitem>
</orderedlist>
<simpara>via the <emphasis>--exclude-from=</emphasis> option.</simpara>
</simplesect>
<simplesect id="git-ls-files(1)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-read-tree(1)" />, <xref linkend="gitignore(5)" /></simpara>
</simplesect>
<simplesect id="git-ls-files(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
