Documentation / git-rm.txton commit fetch and pull: learn --progress (9839018)
   1git-rm(1)
   2=========
   3
   4NAME
   5----
   6git-rm - Remove files from the working tree and from the index
   7
   8SYNOPSIS
   9--------
  10'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
  11
  12DESCRIPTION
  13-----------
  14Remove files from the index, or from the working tree and the index.
  15`git rm` will not remove a file from just your working directory.
  16(There is no option to remove a file only from the working tree
  17and yet keep it in the index; use `/bin/rm` if you want to do that.)
  18The files being removed have to be identical to the tip of the branch,
  19and no updates to their contents can be staged in the index,
  20though that default behavior can be overridden with the `-f` option.
  21When `--cached` is given, the staged content has to
  22match either the tip of the branch or the file on disk,
  23allowing the file to be removed from just the index.
  24
  25
  26OPTIONS
  27-------
  28<file>...::
  29        Files to remove.  Fileglobs (e.g. `*.c`) can be given to
  30        remove all matching files.  If you want git to expand
  31        file glob characters, you may need to shell-escape them.
  32        A leading directory name
  33        (e.g. `dir` to remove `dir/file1` and `dir/file2`) can be
  34        given to remove all files in the directory, and recursively
  35        all sub-directories,
  36        but this requires the `-r` option to be explicitly given.
  37
  38-f::
  39--force::
  40        Override the up-to-date check.
  41
  42-n::
  43--dry-run::
  44        Don't actually remove any file(s).  Instead, just show
  45        if they exist in the index and would otherwise be removed
  46        by the command.
  47
  48-r::
  49        Allow recursive removal when a leading directory name is
  50        given.
  51
  52\--::
  53        This option can be used to separate command-line options from
  54        the list of files, (useful when filenames might be mistaken
  55        for command-line options).
  56
  57--cached::
  58        Use this option to unstage and remove paths only from the index.
  59        Working tree files, whether modified or not, will be
  60        left alone.
  61
  62--ignore-unmatch::
  63        Exit with a zero status even if no files matched.
  64
  65-q::
  66--quiet::
  67        `git rm` normally outputs one line (in the form of an `rm` command)
  68        for each file removed. This option suppresses that output.
  69
  70
  71DISCUSSION
  72----------
  73
  74The <file> list given to the command can be exact pathnames,
  75file glob patterns, or leading directory names.  The command
  76removes only the paths that are known to git.  Giving the name of
  77a file that you have not told git about does not remove that file.
  78
  79File globbing matches across directory boundaries.  Thus, given
  80two directories `d` and `d2`, there is a difference between
  81using `git rm \'d\*\'` and `git rm \'d/\*\'`, as the former will
  82also remove all of directory `d2`.
  83
  84REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM
  85--------------------------------------------------------
  86There is no option for `git rm` to remove from the index only
  87the paths that have disappeared from the filesystem. However,
  88depending on the use case, there are several ways that can be
  89done.
  90
  91Using "git commit -a"
  92~~~~~~~~~~~~~~~~~~~~~
  93If you intend that your next commit should record all modifications
  94of tracked files in the working tree and record all removals of
  95files that have been removed from the working tree with `rm`
  96(as opposed to `git rm`), use `git commit -a`, as it will
  97automatically notice and record all removals.  You can also have a
  98similar effect without committing by using `git add -u`.
  99
 100Using "git add -A"
 101~~~~~~~~~~~~~~~~~~
 102When accepting a new code drop for a vendor branch, you probably
 103want to record both the removal of paths and additions of new paths
 104as well as modifications of existing paths.
 105
 106Typically you would first remove all tracked files from the working
 107tree using this command:
 108
 109----------------
 110git ls-files -z | xargs -0 rm -f
 111----------------
 112
 113and then "untar" the new code in the working tree. Alternately
 114you could "rsync" the changes into the working tree.
 115
 116After that, the easiest way to record all removals, additions, and
 117modifications in the working tree is:
 118
 119----------------
 120git add -A
 121----------------
 122
 123See linkgit:git-add[1].
 124
 125Other ways
 126~~~~~~~~~~
 127If all you really want to do is to remove from the index the files
 128that are no longer present in the working tree (perhaps because
 129your working tree is dirty so that you cannot use `git commit -a`),
 130use the following command:
 131
 132----------------
 133git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
 134----------------
 135
 136EXAMPLES
 137--------
 138git rm Documentation/\\*.txt::
 139        Removes all `\*.txt` files from the index that are under the
 140        `Documentation` directory and any of its subdirectories.
 141+
 142Note that the asterisk `\*` is quoted from the shell in this
 143example; this lets git, and not the shell, expand the pathnames
 144of files and subdirectories under the `Documentation/` directory.
 145
 146git rm -f git-*.sh::
 147        Because this example lets the shell expand the asterisk
 148        (i.e. you are listing the files explicitly), it
 149        does not remove `subdir/git-foo.sh`.
 150
 151SEE ALSO
 152--------
 153linkgit:git-add[1]
 154
 155Author
 156------
 157Written by Linus Torvalds <torvalds@osdl.org>
 158
 159Documentation
 160--------------
 161Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 162
 163GIT
 164---
 165Part of the linkgit:git[1] suite