Update Git docs to 2.29.2
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-rm.xml
blobb568af290872b649bdf19c72a449c20d98a64eed
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">\r
3 \r
4 <sect2 lang="en" id="git-rm(1)">\r
5     <title>git-rm(1)</title>\r
6 <indexterm>\r
7 <primary>git-rm(1)</primary>\r
8 </indexterm>\r
9 <simplesect id="git-rm(1)__name">\r
10 <title>NAME</title>\r
11 <simpara>git-rm - Remove files from the working tree and from the index</simpara>\r
12 </simplesect>\r
13 <simplesect id="git-rm(1)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <blockquote>\r
16 <literallayout><emphasis>git rm</emphasis> [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]\r
17           [--quiet] [--pathspec-from-file=&lt;file&gt; [--pathspec-file-nul]]\r
18           [--] [&lt;pathspec&gt;&#8230;]</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="git-rm(1)__description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Remove files matching pathspec from the index, or from the working tree\r
24 and the index. <emphasis>git rm</emphasis> will not remove a file from just your working\r
25 directory. (There is no option to remove a file only from the working\r
26 tree and yet keep it in the index; use <emphasis>/bin/rm</emphasis> if you want to do\r
27 that.) The files being removed have to be identical to the tip of the\r
28 branch, and no updates to their contents can be staged in the index,\r
29 though that default behavior can be overridden with the <emphasis>-f</emphasis> option.\r
30 When <emphasis>--cached</emphasis> is given, the staged content has to\r
31 match either the tip of the branch or the file on disk,\r
32 allowing the file to be removed from just the index.</simpara>\r
33 </simplesect>\r
34 <simplesect id="git-rm(1)__options">\r
35 <title>OPTIONS</title>\r
36 <variablelist>\r
37 <varlistentry>\r
38 <term>\r
39 &lt;pathspec&gt;&#8230;\r
40 </term>\r
41 <listitem>\r
42 <simpara>\r
43         Files to remove.  A leading directory name (e.g. <emphasis>dir</emphasis> to remove\r
44         <emphasis>dir/file1</emphasis> and <emphasis>dir/file2</emphasis>) can be given to remove all files in\r
45         the directory, and recursively all sub-directories, but this\r
46         requires the <emphasis>-r</emphasis> option to be explicitly given.\r
47 </simpara>\r
48 <simpara>The command removes only the paths that are known to Git.</simpara>\r
49 <simpara>File globbing matches across directory boundaries.  Thus, given two\r
50 directories <emphasis>d</emphasis> and <emphasis>d2</emphasis>, there is a difference between using\r
51 <emphasis>git rm 'd*'</emphasis> and <emphasis>git rm 'd/*'</emphasis>, as the former will also remove all\r
52 of directory <emphasis>d2</emphasis>.</simpara>\r
53 <simpara>For more details, see the <emphasis>pathspec</emphasis> entry in <xref linkend="gitglossary(7)" />.</simpara>\r
54 </listitem>\r
55 </varlistentry>\r
56 <varlistentry>\r
57 <term>\r
58 -f\r
59 </term>\r
60 <term>\r
61 --force\r
62 </term>\r
63 <listitem>\r
64 <simpara>\r
65         Override the up-to-date check.\r
66 </simpara>\r
67 </listitem>\r
68 </varlistentry>\r
69 <varlistentry>\r
70 <term>\r
71 -n\r
72 </term>\r
73 <term>\r
74 --dry-run\r
75 </term>\r
76 <listitem>\r
77 <simpara>\r
78         Don't actually remove any file(s).  Instead, just show\r
79         if they exist in the index and would otherwise be removed\r
80         by the command.\r
81 </simpara>\r
82 </listitem>\r
83 </varlistentry>\r
84 <varlistentry>\r
85 <term>\r
86 -r\r
87 </term>\r
88 <listitem>\r
89 <simpara>\r
90         Allow recursive removal when a leading directory name is\r
91         given.\r
92 </simpara>\r
93 </listitem>\r
94 </varlistentry>\r
95 <varlistentry>\r
96 <term>\r
97 --\r
98 </term>\r
99 <listitem>\r
100 <simpara>\r
101         This option can be used to separate command-line options from\r
102         the list of files, (useful when filenames might be mistaken\r
103         for command-line options).\r
104 </simpara>\r
105 </listitem>\r
106 </varlistentry>\r
107 <varlistentry>\r
108 <term>\r
109 --cached\r
110 </term>\r
111 <listitem>\r
112 <simpara>\r
113         Use this option to unstage and remove paths only from the index.\r
114         Working tree files, whether modified or not, will be\r
115         left alone.\r
116 </simpara>\r
117 </listitem>\r
118 </varlistentry>\r
119 <varlistentry>\r
120 <term>\r
121 --ignore-unmatch\r
122 </term>\r
123 <listitem>\r
124 <simpara>\r
125         Exit with a zero status even if no files matched.\r
126 </simpara>\r
127 </listitem>\r
128 </varlistentry>\r
129 <varlistentry>\r
130 <term>\r
131 -q\r
132 </term>\r
133 <term>\r
134 --quiet\r
135 </term>\r
136 <listitem>\r
137 <simpara>\r
138         <emphasis>git rm</emphasis> normally outputs one line (in the form of an <emphasis>rm</emphasis> command)\r
139         for each file removed. This option suppresses that output.\r
140 </simpara>\r
141 </listitem>\r
142 </varlistentry>\r
143 <varlistentry>\r
144 <term>\r
145 --pathspec-from-file=&lt;file&gt;\r
146 </term>\r
147 <listitem>\r
148 <simpara>\r
149         Pathspec is passed in <emphasis>&lt;file&gt;</emphasis> instead of commandline args. If\r
150         <emphasis>&lt;file&gt;</emphasis> is exactly <emphasis>-</emphasis> then standard input is used. Pathspec\r
151         elements are separated by LF or CR/LF. Pathspec elements can be\r
152         quoted as explained for the configuration variable <emphasis>core.quotePath</emphasis>\r
153         (see <xref linkend="git-config(1)" />). See also <emphasis>--pathspec-file-nul</emphasis> and\r
154         global <emphasis>--literal-pathspecs</emphasis>.\r
155 </simpara>\r
156 </listitem>\r
157 </varlistentry>\r
158 <varlistentry>\r
159 <term>\r
160 --pathspec-file-nul\r
161 </term>\r
162 <listitem>\r
163 <simpara>\r
164         Only meaningful with <emphasis>--pathspec-from-file</emphasis>. Pathspec elements are\r
165         separated with NUL character and all other characters are taken\r
166         literally (including newlines and quotes).\r
167 </simpara>\r
168 </listitem>\r
169 </varlistentry>\r
170 </variablelist>\r
171 </simplesect>\r
172 <simplesect id="git-rm(1)__removing_files_that_have_disappeared_from_the_filesystem">\r
173 <title>REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM</title>\r
174 <simpara>There is no option for <emphasis>git rm</emphasis> to remove from the index only\r
175 the paths that have disappeared from the filesystem. However,\r
176 depending on the use case, there are several ways that can be\r
177 done.</simpara>\r
178 <section id="git-rm(1)__using_git_commit_a">\r
179 <title>Using git commit -a</title>\r
180 <simpara>If you intend that your next commit should record all modifications\r
181 of tracked files in the working tree and record all removals of\r
182 files that have been removed from the working tree with <emphasis>rm</emphasis>\r
183 (as opposed to <emphasis>git rm</emphasis>), use <emphasis>git commit -a</emphasis>, as it will\r
184 automatically notice and record all removals.  You can also have a\r
185 similar effect without committing by using <emphasis>git add -u</emphasis>.</simpara>\r
186 </section>\r
187 <section id="git-rm(1)__using_git_add_a">\r
188 <title>Using git add -A</title>\r
189 <simpara>When accepting a new code drop for a vendor branch, you probably\r
190 want to record both the removal of paths and additions of new paths\r
191 as well as modifications of existing paths.</simpara>\r
192 <simpara>Typically you would first remove all tracked files from the working\r
193 tree using this command:</simpara>\r
194 <screen>git ls-files -z | xargs -0 rm -f</screen>\r
195 <simpara>and then untar the new code in the working tree. Alternately\r
196 you could <emphasis>rsync</emphasis> the changes into the working tree.</simpara>\r
197 <simpara>After that, the easiest way to record all removals, additions, and\r
198 modifications in the working tree is:</simpara>\r
199 <screen>git add -A</screen>\r
200 <simpara>See <xref linkend="git-add(1)" />.</simpara>\r
201 </section>\r
202 <section id="git-rm(1)__other_ways">\r
203 <title>Other ways</title>\r
204 <simpara>If all you really want to do is to remove from the index the files\r
205 that are no longer present in the working tree (perhaps because\r
206 your working tree is dirty so that you cannot use <emphasis>git commit -a</emphasis>),\r
207 use the following command:</simpara>\r
208 <screen>git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached</screen>\r
209 </section>\r
210 </simplesect>\r
211 <simplesect id="git-rm(1)__submodules">\r
212 <title>SUBMODULES</title>\r
213 <simpara>Only submodules using a gitfile (which means they were cloned\r
214 with a Git version 1.7.8 or newer) will be removed from the work\r
215 tree, as their repository lives inside the .git directory of the\r
216 superproject. If a submodule (or one of those nested inside it)\r
217 still uses a .git directory, <emphasis>git rm</emphasis> will move the submodules\r
218 git directory into the superprojects git directory to protect\r
219 the submodule's history. If it exists the submodule.&lt;name&gt; section\r
220 in the <xref linkend="gitmodules(5)" /> file will also be removed and that file\r
221 will be staged (unless --cached or -n are used).</simpara>\r
222 <simpara>A submodule is considered up to date when the HEAD is the same as\r
223 recorded in the index, no tracked files are modified and no untracked\r
224 files that aren't ignored are present in the submodules work tree.\r
225 Ignored files are deemed expendable and won't stop a submodule's work\r
226 tree from being removed.</simpara>\r
227 <simpara>If you only want to remove the local checkout of a submodule from your\r
228 work tree without committing the removal, use <xref linkend="git-submodule(1)" /> <emphasis>deinit</emphasis>\r
229 instead. Also see <xref linkend="gitsubmodules(7)" /> for details on submodule removal.</simpara>\r
230 </simplesect>\r
231 <simplesect id="git-rm(1)__examples">\r
232 <title>EXAMPLES</title>\r
233 <variablelist>\r
234 <varlistentry>\r
235 <term>\r
236 <emphasis>git rm Documentation/\*.txt</emphasis>\r
237 </term>\r
238 <listitem>\r
239 <simpara>\r
240         Removes all <emphasis>*.txt</emphasis> files from the index that are under the\r
241         <emphasis>Documentation</emphasis> directory and any of its subdirectories.\r
242 </simpara>\r
243 <simpara>Note that the asterisk <emphasis>*</emphasis> is quoted from the shell in this\r
244 example; this lets Git, and not the shell, expand the pathnames\r
245 of files and subdirectories under the <emphasis>Documentation/</emphasis> directory.</simpara>\r
246 </listitem>\r
247 </varlistentry>\r
248 <varlistentry>\r
249 <term>\r
250 <emphasis>git rm -f git-*.sh</emphasis>\r
251 </term>\r
252 <listitem>\r
253 <simpara>\r
254         Because this example lets the shell expand the asterisk\r
255         (i.e. you are listing the files explicitly), it\r
256         does not remove <emphasis>subdir/git-foo.sh</emphasis>.\r
257 </simpara>\r
258 </listitem>\r
259 </varlistentry>\r
260 </variablelist>\r
261 </simplesect>\r
262 <simplesect id="git-rm(1)__bugs">\r
263 <title>BUGS</title>\r
264 <simpara>Each time a superproject update removes a populated submodule\r
265 (e.g. when switching between commits before and after the removal) a\r
266 stale submodule checkout will remain in the old location. Removing the\r
267 old directory is only safe when it uses a gitfile, as otherwise the\r
268 history of the submodule will be deleted too. This step will be\r
269 obsolete when recursive submodule update has been implemented.</simpara>\r
270 </simplesect>\r
271 <simplesect id="git-rm(1)__see_also">\r
272 <title>SEE ALSO</title>\r
273 <simpara><xref linkend="git-add(1)" /></simpara>\r
274 </simplesect>\r
275 <simplesect id="git-rm(1)__git">\r
276 <title>GIT</title>\r
277 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
278 </simplesect>\r
279 </sect2>\r