3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.47.1.397.g23692e08c6
10 .TH "GIT\-RM" "1" "2024-12-04" "Git 2\&.47\&.1\&.397\&.g23692e" "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>\&...\:]
41 Remove files matching pathspec from the index, or from the working tree and the index\&. \fBgit\fR \fBrm\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\fR \fBrm\fR will only remove paths within the sparse\-checkout patterns\&.
46 Files to remove\&. A leading directory name (e\&.g\&.
51 \fBdir/file2\fR) can be given to remove all files in the directory, and recursively all sub\-directories, but this requires the
53 option to be explicitly given\&.
55 The command removes only the paths that are known to Git\&.
57 File globbing matches across directory boundaries\&. Thus, given two directories
60 \fBd2\fR, there is a difference between using
66 \*(Aqd/*\*(Aq, as the former will also remove all of directory
69 For more details, see the
72 \fBgitglossary\fR(7)\&.
77 Override the up\-to\-date check\&.
82 Don\(cqt actually remove any file(s)\&. Instead, just show if they exist in the index and would otherwise be removed by the command\&.
87 Allow recursive removal when a leading directory name is given\&.
92 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)\&.
97 Use this option to unstage and remove paths only from the index\&. Working tree files, whether modified or not, will be left alone\&.
102 Exit with a zero status even if no files matched\&.
107 Allow updating index entries outside of the sparse\-checkout cone\&. Normally,
110 refuses to update index entries whose paths do not fit within the sparse\-checkout cone\&. See
111 \fBgit-sparse-checkout\fR(1)
119 normally outputs one line (in the form of an
121 command) for each file removed\&. This option suppresses that output\&.
124 \-\-pathspec\-from\-file=<file>
126 Pathspec is passed in
128 instead of commandline args\&. If
132 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
133 \fBcore\&.quotePath\fR
135 \fBgit-config\fR(1))\&. See also
136 \fB\-\-pathspec\-file\-nul\fR
138 \fB\-\-literal\-pathspecs\fR\&.
141 \-\-pathspec\-file\-nul
144 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
146 .SH "REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM"
148 There is no option for \fBgit\fR \fBrm\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\&.
149 .SS "Using \(lqgit commit \-a\(rq"
151 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\fR \fBrm\fR), use \fBgit\fR \fBcommit\fR \fB\-a\fR, as it will automatically notice and record all removals\&. You can also have a similar effect without committing by using \fBgit\fR \fBadd\fR \fB\-u\fR\&.
152 .SS "Using \(lqgit add \-A\(rq"
154 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\&.
156 Typically you would first remove all tracked files from the working tree using this command:
162 git ls\-files \-z | xargs \-0 rm \-f
168 and then untar the new code in the working tree\&. Alternately you could \fIrsync\fR the changes into the working tree\&.
170 After that, the easiest way to record all removals, additions, and modifications in the working tree is:
182 See \fBgit-add\fR(1)\&.
185 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\fR \fBcommit\fR \fB\-a\fR), use the following command:
191 git diff \-\-name\-only \-\-diff\-filter=D \-z | xargs \-0 git rm \-\-cached
198 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\fR \fBrm\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)\&.
200 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 submodule\(cqs work tree\&. Ignored files are deemed expendable and won\(cqt stop a submodule\(cqs work tree from being removed\&.
202 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\&.
205 \fBgit\fR \fBrm\fR \fBDocumentation/\fR\e*\&.\fBtxt\fR
207 Removes all *\&.\fBtxt\fR
208 files from the index that are under the
210 directory and any of its subdirectories\&.
212 Note that the asterisk * is quoted from the shell in this example; this lets Git, and not the shell, expand the pathnames of files and subdirectories under the
217 \fBgit\fR \fBrm\fR \fB\-f\fR \fBgit\-\fR*\&.\fBsh\fR
219 Because this example lets the shell expand the asterisk (i\&.e\&. you are listing the files explicitly), it does not remove
220 \fBsubdir/git\-foo\&.sh\fR\&.
224 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\&.
230 Part of the \fBgit\fR(1) suite