3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.34.1.182.ge773545c7f
10 .TH "GIT\-RM" "1" "12/10/2021" "Git 2\&.34\&.1\&.182\&.ge77354" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-rm \- Remove files from the working tree and from the index
35 \fIgit rm\fR [\-f | \-\-force] [\-n] [\-r] [\-\-cached] [\-\-ignore\-unmatch]
36 [\-\-quiet] [\-\-pathspec\-from\-file=<file> [\-\-pathspec\-file\-nul]]
37 [\-\-] [<pathspec>\&...]
42 Remove files matching pathspec from the index, or from the working tree and the index\&. \fBgit rm\fR will not remove a file from just your working directory\&. (There is no option to remove a file only from the working tree and yet keep it in the index; use \fB/bin/rm\fR if you want to do that\&.) The files being removed have to be identical to the tip of the branch, and no updates to their contents can be staged in the index, though that default behavior can be overridden with the \fB\-f\fR option\&. When \fB\-\-cached\fR is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index\&. When sparse\-checkouts are in use (see \fBgit-sparse-checkout\fR(1)), \fBgit rm\fR will only remove paths within the sparse\-checkout patterns\&.
47 Files to remove\&. A leading directory name (e\&.g\&.
52 \fBdir/file2\fR) can be given to remove all files in the directory, and recursively all sub\-directories, but this requires the
54 option to be explicitly given\&.
56 The command removes only the paths that are known to Git\&.
58 File globbing matches across directory boundaries\&. Thus, given two directories
61 \fBd2\fR, there is a difference between using
62 \fBgit rm \(aqd*\(aq\fR
64 \fBgit rm \(aqd/*\(aq\fR, as the former will also remove all of directory
67 For more details, see the
70 \fBgitglossary\fR(7)\&.
75 Override the up\-to\-date check\&.
80 Don\(cqt actually remove any file(s)\&. Instead, just show if they exist in the index and would otherwise be removed by the command\&.
85 Allow recursive removal when a leading directory name is given\&.
90 This option can be used to separate command\-line options from the list of files, (useful when filenames might be mistaken for command\-line options)\&.
95 Use this option to unstage and remove paths only from the index\&. Working tree files, whether modified or not, will be left alone\&.
100 Exit with a zero status even if no files matched\&.
105 Allow updating index entries outside of the sparse\-checkout cone\&. Normally,
107 refuses to update index entries whose paths do not fit within the sparse\-checkout cone\&. See
108 \fBgit-sparse-checkout\fR(1)
115 normally outputs one line (in the form of an
117 command) for each file removed\&. This option suppresses that output\&.
120 \-\-pathspec\-from\-file=<file>
122 Pathspec is passed in
124 instead of commandline args\&. If
128 then standard input is used\&. Pathspec elements are separated by LF or CR/LF\&. Pathspec elements can be quoted as explained for the configuration variable
129 \fBcore\&.quotePath\fR
131 \fBgit-config\fR(1))\&. See also
132 \fB\-\-pathspec\-file\-nul\fR
134 \fB\-\-literal\-pathspecs\fR\&.
137 \-\-pathspec\-file\-nul
140 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
142 .SH "REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM"
144 There is no option for \fBgit rm\fR to remove from the index only the paths that have disappeared from the filesystem\&. However, depending on the use case, there are several ways that can be done\&.
145 .SS "Using \(lqgit commit \-a\(rq"
147 If you intend that your next commit should record all modifications of tracked files in the working tree and record all removals of files that have been removed from the working tree with \fBrm\fR (as opposed to \fBgit rm\fR), use \fBgit commit \-a\fR, as it will automatically notice and record all removals\&. You can also have a similar effect without committing by using \fBgit add \-u\fR\&.
148 .SS "Using \(lqgit add \-A\(rq"
150 When accepting a new code drop for a vendor branch, you probably want to record both the removal of paths and additions of new paths as well as modifications of existing paths\&.
152 Typically you would first remove all tracked files from the working tree using this command:
158 git ls\-files \-z | xargs \-0 rm \-f
165 and then untar the new code in the working tree\&. Alternately you could \fIrsync\fR the changes into the working tree\&.
167 After that, the easiest way to record all removals, additions, and modifications in the working tree is:
180 See \fBgit-add\fR(1)\&.
183 If all you really want to do is to remove from the index the files that are no longer present in the working tree (perhaps because your working tree is dirty so that you cannot use \fBgit commit \-a\fR), use the following command:
189 git diff \-\-name\-only \-\-diff\-filter=D \-z | xargs \-0 git rm \-\-cached
197 Only submodules using a gitfile (which means they were cloned with a Git version 1\&.7\&.8 or newer) will be removed from the work tree, as their repository lives inside the \&.git directory of the superproject\&. If a submodule (or one of those nested inside it) still uses a \&.git directory, \fBgit rm\fR will move the submodules git directory into the superprojects git directory to protect the submodule\(cqs history\&. If it exists the submodule\&.<name> section in the \fBgitmodules\fR(5) file will also be removed and that file will be staged (unless \-\-cached or \-n are used)\&.
199 A submodule is considered up to date when the HEAD is the same as recorded in the index, no tracked files are modified and no untracked files that aren\(cqt ignored are present in the submodules work tree\&. Ignored files are deemed expendable and won\(cqt stop a submodule\(cqs work tree from being removed\&.
201 If you only want to remove the local checkout of a submodule from your work tree without committing the removal, use \fBgit-submodule\fR(1) \fBdeinit\fR instead\&. Also see \fBgitsubmodules\fR(7) for details on submodule removal\&.
204 \fBgit rm Documentation/\e*\&.txt\fR
208 files from the index that are under the
210 directory and any of its subdirectories\&.
212 Note that the asterisk
214 is quoted from the shell in this example; this lets Git, and not the shell, expand the pathnames of files and subdirectories under the
219 \fBgit rm \-f git\-*\&.sh\fR
221 Because this example lets the shell expand the asterisk (i\&.e\&. you are listing the files explicitly), it does not remove
222 \fBsubdir/git\-foo\&.sh\fR\&.
226 Each time a superproject update removes a populated submodule (e\&.g\&. when switching between commits before and after the removal) a stale submodule checkout will remain in the old location\&. Removing the old directory is only safe when it uses a gitfile, as otherwise the history of the submodule will be deleted too\&. This step will be obsolete when recursive submodule update has been implemented\&.
232 Part of the \fBgit\fR(1) suite