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.0.rc0
10 .TH "GIT\-RM" "1" "2024-09-25" "Git 2\&.47\&.0\&.rc0" "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 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\&.
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
61 \fBgit rm \*(Aqd*\*(Aq\fR
63 \fBgit rm \*(Aqd/*\*(Aq\fR, as the former will also remove all of directory
66 For more details, see the
69 \fBgitglossary\fR(7)\&.
74 Override the up\-to\-date check\&.
79 Don\(cqt actually remove any file(s)\&. Instead, just show if they exist in the index and would otherwise be removed by the command\&.
84 Allow recursive removal when a leading directory name is given\&.
89 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)\&.
94 Use this option to unstage and remove paths only from the index\&. Working tree files, whether modified or not, will be left alone\&.
99 Exit with a zero status even if no files matched\&.
104 Allow updating index entries outside of the sparse\-checkout cone\&. Normally,
106 refuses to update index entries whose paths do not fit within the sparse\-checkout cone\&. See
107 \fBgit-sparse-checkout\fR(1)
114 normally outputs one line (in the form of an
116 command) for each file removed\&. This option suppresses that output\&.
119 \-\-pathspec\-from\-file=<file>
121 Pathspec is passed in
123 instead of commandline args\&. If
127 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
128 \fBcore\&.quotePath\fR
130 \fBgit-config\fR(1))\&. See also
131 \fB\-\-pathspec\-file\-nul\fR
133 \fB\-\-literal\-pathspecs\fR\&.
136 \-\-pathspec\-file\-nul
139 \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
141 .SH "REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM"
143 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\&.
144 .SS "Using \(lqgit commit \-a\(rq"
146 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\&.
147 .SS "Using \(lqgit add \-A\(rq"
149 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\&.
151 Typically you would first remove all tracked files from the working tree using this command:
157 git ls\-files \-z | xargs \-0 rm \-f
163 and then untar the new code in the working tree\&. Alternately you could \fIrsync\fR the changes into the working tree\&.
165 After that, the easiest way to record all removals, additions, and modifications in the working tree is:
177 See \fBgit-add\fR(1)\&.
180 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:
186 git diff \-\-name\-only \-\-diff\-filter=D \-z | xargs \-0 git rm \-\-cached
193 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)\&.
195 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\&.
197 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\&.
200 \fBgit rm Documentation/\e*\&.txt\fR
204 files from the index that are under the
206 directory and any of its subdirectories\&.
208 Note that the asterisk
210 is quoted from the shell in this example; this lets Git, and not the shell, expand the pathnames of files and subdirectories under the
215 \fBgit rm \-f git\-*\&.sh\fR
217 Because this example lets the shell expand the asterisk (i\&.e\&. you are listing the files explicitly), it does not remove
218 \fBsubdir/git\-foo\&.sh\fR\&.
222 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\&.
228 Part of the \fBgit\fR(1) suite