<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="git-update-index(1)">
<articleinfo>
    <title>git-update-index(1)</title>
        <indexterm>
                <primary>git-update-index(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-update-index - Register file contents in the working tree to the index</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git update-index</emphasis>
             [--add] [--remove | --force-remove] [--replace]
             [--refresh] [-q] [--unmerged] [--ignore-missing]
             [--cacheinfo &lt;mode&gt; &lt;object&gt; &lt;file&gt;]*
             [--chmod=(+|-)x]
             [--assume-unchanged | --no-assume-unchanged]
             [--ignore-submodules]
             [--really-refresh] [--unresolve] [--again | -g]
             [--info-only] [--index-info]
             [-z] [--stdin]
             [--verbose]
             [--] [&lt;file&gt;]\*</literallayout>
</blockquote>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Modifies the index or directory cache. Each file mentioned is updated
into the index and any <emphasis>unmerged</emphasis> or <emphasis>needs updating</emphasis> state is
cleared.</simpara>
<simpara>See also <xref linkend="git-add(1)"/> for a more user-friendly way to do some of
the most common operations on the index.</simpara>
<simpara>The way <emphasis>git-update-index</emphasis> handles files it is told about can be modified
using the various options:</simpara>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--add
</term>
<listitem>
<simpara>
        If a specified file isn&#8217;t in the index already then it&#8217;s
        added.
        Default behaviour is to ignore new files.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--remove
</term>
<listitem>
<simpara>
        If a specified file is in the index but is missing then it&#8217;s
        removed.
        Default behavior is to ignore removed file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--refresh
</term>
<listitem>
<simpara>
        Looks at the current index and checks to see if merges or
        updates are needed by checking stat() information.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-q
</term>
<listitem>
<simpara>
        Quiet.  If --refresh finds that the index needs an update, the
        default behavior is to error out.  This option makes
        <emphasis>git-update-index</emphasis> continue anyway.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ignore-submodules
</term>
<listitem>
<simpara>
        Do not try to update submodules.  This option is only respected
        when passed before --refresh.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--unmerged
</term>
<listitem>
<simpara>
        If --refresh finds unmerged changes in the index, the default
        behavior is to error out.  This option makes <emphasis>git-update-index</emphasis>
        continue anyway.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ignore-missing
</term>
<listitem>
<simpara>
        Ignores missing files during a --refresh
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--cacheinfo &lt;mode&gt; &lt;object&gt; &lt;path&gt;
</term>
<listitem>
<simpara>
        Directly insert the specified info into the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--index-info
</term>
<listitem>
<simpara>
        Read index information from stdin.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--chmod=(+|-)x
</term>
<listitem>
<simpara>
        Set the execute permissions on the updated files.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--assume-unchanged
</term>
<term>
--no-assume-unchanged
</term>
<listitem>
<simpara>
        When these flags are specified, the object names recorded
        for the paths are not updated.  Instead, these options
        set and unset the "assume unchanged" bit for the
        paths.  When the "assume unchanged" bit is on, git stops
        checking the working tree files for possible
        modifications, so you need to manually unset the bit to
        tell git when you change the working tree file. This is
        sometimes helpful when working with a big project on a
        filesystem that has very slow lstat(2) system call
        (e.g. cifs).
</simpara>
<simpara>This option can be also used as a coarse file-level mechanism
to ignore uncommitted changes in tracked files (akin to what
<literal>.gitignore</literal> does for untracked files).
You should remember that an explicit <emphasis>git add</emphasis> operation will
still cause the file to be refreshed from the working tree.
Git will fail (gracefully) in case it needs to modify this file
in the index e.g. when merging in a commit;
thus, in case the assumed-untracked file is changed upstream,
you will need to handle the situation manually.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-g
</term>
<term>
--again
</term>
<listitem>
<simpara>
        Runs <emphasis>git-update-index</emphasis> itself on the paths whose index
        entries are different from those from the <literal>HEAD</literal> commit.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--unresolve
</term>
<listitem>
<simpara>
        Restores the <emphasis>unmerged</emphasis> or <emphasis>needs updating</emphasis> state of a
        file during a merge if it was cleared by accident.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--info-only
</term>
<listitem>
<simpara>
        Do not create objects in the object database for all
        &lt;file&gt; arguments that follow this flag; just insert
        their object IDs into the index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--force-remove
</term>
<listitem>
<simpara>
        Remove the file from the index even when the working directory
        still has such a file. (Implies --remove.)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--replace
</term>
<listitem>
<simpara>
        By default, when a file <literal>path</literal> exists in the index,
        <emphasis>git-update-index</emphasis> refuses an attempt to add <literal>path/file</literal>.
        Similarly if a file <literal>path/file</literal> exists, a file <literal>path</literal>
        cannot be added.  With --replace flag, existing entries
        that conflict with the entry being added are
        automatically removed with warning messages.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--stdin
</term>
<listitem>
<simpara>
        Instead of taking list of paths from the command line,
        read list of paths from the standard input.  Paths are
        separated by LF (i.e. one path per line) by default.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--verbose
</term>
<listitem>
<simpara>
        Report what is being added and removed from index.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-z
</term>
<listitem>
<simpara>
        Only meaningful with <literal>--stdin</literal>; paths are separated with
        NUL character instead of LF.
</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 act on.
        Note that files beginning with <emphasis>.</emphasis> are discarded. This includes
        <literal>./file</literal> and <literal>dir/./file</literal>. If you don&#8217;t want this, then use
        cleaner names.
        The same applies to directories ending <emphasis>/</emphasis> and paths with <emphasis>//</emphasis>
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_using_refresh">
<title>Using --refresh</title>
<simpara><emphasis>--refresh</emphasis> does not calculate a new sha1 file or bring the index
up-to-date for mode/content changes. But what it <emphasis role="strong">does</emphasis> do is to
"re-match" the stat information of a file with the index, so that you
can refresh the index for a file that hasn&#8217;t been changed but where
the stat entry is out of date.</simpara>
<simpara>For example, you&#8217;d want to do this after doing a <emphasis>git-read-tree</emphasis>, to link
up the stat index details with the proper files.</simpara>
</simplesect>
<simplesect id="_using_cacheinfo_or_info_only">
<title>Using --cacheinfo or --info-only</title>
<simpara><emphasis>--cacheinfo</emphasis> is used to register a file that is not in the
current working directory.  This is useful for minimum-checkout
merging.</simpara>
<simpara>To pretend you have a file with mode and sha1 at path, say:</simpara>
<literallayout>$ git update-index --cacheinfo mode sha1 path</literallayout>
<simpara><emphasis>--info-only</emphasis> is used to register files without placing them in the object
database.  This is useful for status-only repositories.</simpara>
<simpara>Both <emphasis>--cacheinfo</emphasis> and <emphasis>--info-only</emphasis> behave similarly: the index is updated
but the object database isn&#8217;t.  <emphasis>--cacheinfo</emphasis> is useful when the object is
in the database but the file isn&#8217;t available locally.  <emphasis>--info-only</emphasis> is
useful when the file is available, but you do not wish to update the
object database.</simpara>
</simplesect>
<simplesect id="_using_index_info">
<title>Using --index-info</title>
<simpara><literal>--index-info</literal> is a more powerful mechanism that lets you feed
multiple entry definitions from the standard input, and designed
specifically for scripts.  It can take inputs of three formats:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
mode         SP sha1          TAB path
</simpara>
<simpara>The first format is what "git-apply --index-info"
reports, and used to reconstruct a partial tree
that is used for phony merge base tree when falling
back on 3-way merge.</simpara>
</listitem>
<listitem>
<simpara>
mode SP type SP sha1          TAB path
</simpara>
<simpara>The second format is to stuff <emphasis>git-ls-tree</emphasis> output
into the index file.</simpara>
</listitem>
<listitem>
<simpara>
mode         SP sha1 SP stage TAB path
</simpara>
<simpara>This format is to put higher order stages into the
index file and matches <emphasis>git-ls-files --stage</emphasis> output.</simpara>
</listitem>
</orderedlist>
<simpara>To place a higher stage entry to the index, the path should
first be removed by feeding a mode=0 entry for the path, and
then feeding necessary input lines in the third format.</simpara>
<simpara>For example, starting with this index:</simpara>
<literallayout>$ git ls-files -s
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0       frotz</literallayout>
<simpara>you can feed the following input to <literal>--index-info</literal>:</simpara>
<literallayout>$ git update-index --index-info
0 0000000000000000000000000000000000000000      frotz
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz</literallayout>
<simpara>The first line of the input feeds 0 as the mode to remove the
path; the SHA1 does not matter as long as it is well formatted.
Then the second and third line feeds stage 1 and stage 2 entries
for that path.  After the above, we would end up with this:</simpara>
<literallayout>$ git ls-files -s
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1       frotz
100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2       frotz</literallayout>
</simplesect>
<simplesect id="_using_8220_assume_unchanged_8221_bit">
<title>Using &#8220;assume unchanged&#8221; bit</title>
<simpara>Many operations in git depend on your filesystem to have an
efficient <literal>lstat(2)</literal> implementation, so that <literal>st_mtime</literal>
information for working tree files can be cheaply checked to see
if the file contents have changed from the version recorded in
the index file.  Unfortunately, some filesystems have
inefficient <literal>lstat(2)</literal>.  If your filesystem is one of them, you
can set "assume unchanged" bit to paths you have not changed to
cause git not to do this check.  Note that setting this bit on a
path does not mean git will check the contents of the file to
see if it has changed&#8201;&#8212;&#8201;it makes git to omit any checking and
assume it has <emphasis role="strong">not</emphasis> changed.  When you make changes to working
tree files, you have to explicitly tell git about it by dropping
"assume unchanged" bit, either before or after you modify them.</simpara>
<simpara>In order to set "assume unchanged" bit, use <literal>--assume-unchanged</literal>
option.  To unset, use <literal>--no-assume-unchanged</literal>.</simpara>
<simpara>The command looks at <literal>core.ignorestat</literal> configuration variable.  When
this is true, paths updated with <literal>git update-index paths&#8230;</literal> and
paths updated with other git commands that update both index and
working tree (e.g. <emphasis>git-apply --index</emphasis>, <emphasis>git-checkout-index -u</emphasis>,
and <emphasis>git-read-tree -u</emphasis>) are automatically marked as "assume
unchanged".  Note that "assume unchanged" bit is <emphasis role="strong">not</emphasis> set if
<literal>git update-index --refresh</literal> finds the working tree file matches
the index (use <literal>git update-index --really-refresh</literal> if you want
to mark them as "assume unchanged").</simpara>
</simplesect>
<simplesect id="_examples">
<title>Examples</title>
<simpara>To update and refresh only the files already checked out:</simpara>
<literallayout>$ git checkout-index -n -f -a &amp;&amp; git update-index --ignore-missing --refresh</literallayout>
<variablelist>
<varlistentry>
<term>
On an inefficient filesystem with <literal>core.ignorestat</literal> set
</term>
<listitem>
<literallayout>$ git update-index --really-refresh              <co id="CO1-1"/>
$ git update-index --no-assume-unchanged foo.c   <co id="CO1-2"/>
$ git diff --name-only                           <co id="CO1-3"/>
$ edit foo.c
$ git diff --name-only                           <co id="CO1-4"/>
M foo.c
$ git update-index foo.c                         <co id="CO1-5"/>
$ git diff --name-only                           <co id="CO1-6"/>
$ edit foo.c
$ git diff --name-only                           <co id="CO1-7"/>
$ git update-index --no-assume-unchanged foo.c   <co id="CO1-8"/>
$ git diff --name-only                           <co id="CO1-9"/>
M foo.c</literallayout>
<calloutlist>
<callout arearefs="CO1-1">
<simpara>
forces lstat(2) to set "assume unchanged" bits for paths that match index.
</simpara>
</callout>
<callout arearefs="CO1-2">
<simpara>
mark the path to be edited.
</simpara>
</callout>
<callout arearefs="CO1-3">
<simpara>
this does lstat(2) and finds index matches the path.
</simpara>
</callout>
<callout arearefs="CO1-4">
<simpara>
this does lstat(2) and finds index does <emphasis role="strong">not</emphasis> match the path.
</simpara>
</callout>
<callout arearefs="CO1-5">
<simpara>
registering the new version to index sets "assume unchanged" bit.
</simpara>
</callout>
<callout arearefs="CO1-6">
<simpara>
and it is assumed unchanged.
</simpara>
</callout>
<callout arearefs="CO1-7">
<simpara>
even after you edit it.
</simpara>
</callout>
<callout arearefs="CO1-8">
<simpara>
you can tell about the change after the fact.
</simpara>
</callout>
<callout arearefs="CO1-9">
<simpara>
now it checks with lstat(2) and finds it has been changed.
</simpara>
</callout>
</calloutlist>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_configuration">
<title>Configuration</title>
<simpara>The command honors <literal>core.filemode</literal> configuration variable.  If
your repository is on an filesystem whose executable bits are
unreliable, this should be set to <emphasis>false</emphasis> (see <xref linkend="git-config(1)"/>).
This causes the command to ignore differences in file modes recorded
in the index and the file mode on the filesystem if they differ only on
executable bit.   On such an unfortunate filesystem, you may
need to use <emphasis>git-update-index --chmod=</emphasis>.</simpara>
<simpara>Quite similarly, if <literal>core.symlinks</literal> configuration variable is set
to <emphasis>false</emphasis> (see <xref linkend="git-config(1)"/>), symbolic links are checked out
as plain files, and this command does not modify a recorded file mode
from symbolic link to regular file.</simpara>
<simpara>The command looks at <literal>core.ignorestat</literal> configuration variable.  See
<emphasis>Using "assume unchanged" bit</emphasis> section above.</simpara>
<simpara>The command also looks at <literal>core.trustctime</literal> configuration variable.
It can be useful when the inode change time is regularly modified by
something outside Git (file system crawlers and backup systems use
ctime for marking files processed) (see <xref linkend="git-config(1)"/>).</simpara>
</simplesect>
<simplesect id="_see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-config(1)"/>,
<xref linkend="git-add(1)"/></simpara>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by David Greaves, Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
