]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-rm.txt
rm: honor sparse checkout patterns
[thirdparty/git.git] / Documentation / git-rm.txt
CommitLineData
d4a1cab5
CW
1git-rm(1)
2=========
3
4NAME
5----
7bd7f280 6git-rm - Remove files from the working tree and from the index
d4a1cab5
CW
7
8SYNOPSIS
9--------
7791a1d9 10[verse]
5f393dc3
AM
11'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
12 [--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]
13 [--] [<pathspec>...]
d4a1cab5
CW
14
15DESCRIPTION
16-----------
6a7aca6f
AM
17Remove files matching pathspec from the index, or from the working tree
18and the index. `git rm` will not remove a file from just your working
19directory. (There is no option to remove a file only from the working
20tree and yet keep it in the index; use `/bin/rm` if you want to do
21that.) The files being removed have to be identical to the tip of the
22branch, and no updates to their contents can be staged in the index,
25dc7200 23though that default behavior can be overridden with the `-f` option.
441947f6 24When `--cached` is given, the staged content has to
25dc7200 25match either the tip of the branch or the file on disk,
d5f4b826
MT
26allowing the file to be removed from just the index. When
27sparse-checkouts are in use (see linkgit:git-sparse-checkout[1]),
28`git rm` will only remove paths within the sparse-checkout patterns.
d4a1cab5
CW
29
30
31OPTIONS
32-------
6a7aca6f
AM
33<pathspec>...::
34 Files to remove. A leading directory name (e.g. `dir` to remove
35 `dir/file1` and `dir/file2`) can be given to remove all files in
36 the directory, and recursively all sub-directories, but this
37 requires the `-r` option to be explicitly given.
38+
39The command removes only the paths that are known to Git.
40+
41File globbing matches across directory boundaries. Thus, given two
42directories `d` and `d2`, there is a difference between using
43`git rm 'd*'` and `git rm 'd/*'`, as the former will also remove all
44of directory `d2`.
45+
46For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
d4a1cab5
CW
47
48-f::
01144f20 49--force::
08d22488 50 Override the up-to-date check.
d4a1cab5 51
3240240f
SB
52-n::
53--dry-run::
25dc7200
JL
54 Don't actually remove any file(s). Instead, just show
55 if they exist in the index and would otherwise be removed
56 by the command.
d4a1cab5 57
08d22488
JH
58-r::
59 Allow recursive removal when a leading directory name is
60 given.
d4a1cab5 61
e994004f 62\--::
d4a1cab5
CW
63 This option can be used to separate command-line options from
64 the list of files, (useful when filenames might be mistaken
65 for command-line options).
66
3240240f 67--cached::
25dc7200
JL
68 Use this option to unstage and remove paths only from the index.
69 Working tree files, whether modified or not, will be
70 left alone.
08d22488 71
3240240f 72--ignore-unmatch::
bb1faf0d
SG
73 Exit with a zero status even if no files matched.
74
3240240f
SB
75-q::
76--quiet::
441947f6 77 `git rm` normally outputs one line (in the form of an `rm` command)
b48caa20
SG
78 for each file removed. This option suppresses that output.
79
5f393dc3
AM
80--pathspec-from-file=<file>::
81 Pathspec is passed in `<file>` instead of commandline args. If
82 `<file>` is exactly `-` then standard input is used. Pathspec
83 elements are separated by LF or CR/LF. Pathspec elements can be
84 quoted as explained for the configuration variable `core.quotePath`
85 (see linkgit:git-config[1]). See also `--pathspec-file-nul` and
86 global `--literal-pathspecs`.
87
88--pathspec-file-nul::
89 Only meaningful with `--pathspec-from-file`. Pathspec elements are
90 separated with NUL character and all other characters are taken
91 literally (including newlines and quotes).
92
d4a1cab5 93
47b70120
BG
94REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM
95--------------------------------------------------------
96There is no option for `git rm` to remove from the index only
97the paths that have disappeared from the filesystem. However,
98depending on the use case, there are several ways that can be
99done.
100
f34e9edc
MG
101Using ``git commit -a''
102~~~~~~~~~~~~~~~~~~~~~~~
47b70120
BG
103If you intend that your next commit should record all modifications
104of tracked files in the working tree and record all removals of
105files that have been removed from the working tree with `rm`
106(as opposed to `git rm`), use `git commit -a`, as it will
107automatically notice and record all removals. You can also have a
108similar effect without committing by using `git add -u`.
109
f34e9edc
MG
110Using ``git add -A''
111~~~~~~~~~~~~~~~~~~~~
47b70120
BG
112When accepting a new code drop for a vendor branch, you probably
113want to record both the removal of paths and additions of new paths
114as well as modifications of existing paths.
115
116Typically you would first remove all tracked files from the working
117tree using this command:
118
119----------------
120git ls-files -z | xargs -0 rm -f
121----------------
122
f34e9edc
MG
123and then untar the new code in the working tree. Alternately
124you could 'rsync' the changes into the working tree.
47b70120
BG
125
126After that, the easiest way to record all removals, additions, and
127modifications in the working tree is:
128
129----------------
130git add -A
131----------------
132
133See linkgit:git-add[1].
134
135Other ways
136~~~~~~~~~~
137If all you really want to do is to remove from the index the files
138that are no longer present in the working tree (perhaps because
139your working tree is dirty so that you cannot use `git commit -a`),
140use the following command:
141
142----------------
143git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
144----------------
145
95c16418
JL
146SUBMODULES
147----------
3469c7eb 148Only submodules using a gitfile (which means they were cloned
2de9b711 149with a Git version 1.7.8 or newer) will be removed from the work
3469c7eb
MK
150tree, as their repository lives inside the .git directory of the
151superproject. If a submodule (or one of those nested inside it)
68602c01
SB
152still uses a .git directory, `git rm` will move the submodules
153git directory into the superprojects git directory to protect
154the submodule's history. If it exists the submodule.<name> section
155in the linkgit:gitmodules[5] file will also be removed and that file
156will be staged (unless --cached or -n are used).
3469c7eb 157
7560f547 158A submodule is considered up to date when the HEAD is the same as
3469c7eb
MK
159recorded in the index, no tracked files are modified and no untracked
160files that aren't ignored are present in the submodules work tree.
161Ignored files are deemed expendable and won't stop a submodule's work
162tree from being removed.
163
cf419828 164If you only want to remove the local checkout of a submodule from your
d4803455
SB
165work tree without committing the removal, use linkgit:git-submodule[1] `deinit`
166instead. Also see linkgit:gitsubmodules[7] for details on submodule removal.
cf419828 167
d4a1cab5
CW
168EXAMPLES
169--------
5d2fc913 170`git rm Documentation/\*.txt`::
c300578f 171 Removes all `*.txt` files from the index that are under the
a9877f83 172 `Documentation` directory and any of its subdirectories.
d4a1cab5 173+
c300578f 174Note that the asterisk `*` is quoted from the shell in this
2de9b711 175example; this lets Git, and not the shell, expand the pathnames
25dc7200 176of files and subdirectories under the `Documentation/` directory.
d4a1cab5 177
5d2fc913 178`git rm -f git-*.sh`::
a9877f83
JH
179 Because this example lets the shell expand the asterisk
180 (i.e. you are listing the files explicitly), it
08d22488 181 does not remove `subdir/git-foo.sh`.
d4a1cab5 182
bbad9f93
JL
183BUGS
184----
185Each time a superproject update removes a populated submodule
186(e.g. when switching between commits before and after the removal) a
187stale submodule checkout will remain in the old location. Removing the
188old directory is only safe when it uses a gitfile, as otherwise the
189history of the submodule will be deleted too. This step will be
190obsolete when recursive submodule update has been implemented.
191
56ae8df5 192SEE ALSO
872d001f 193--------
5162e697 194linkgit:git-add[1]
d4a1cab5 195
d4a1cab5
CW
196GIT
197---
9e1f0a85 198Part of the linkgit:git[1] suite