1GIT-RM(1)                         Git Manual                         GIT-RM(1)
2
3
4

NAME

6       git-rm - Remove files from the working tree and from the index
7

SYNOPSIS

9       git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
10                 [--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]
11                 [--] [<pathspec>...]
12

DESCRIPTION

14       Remove files matching pathspec from the index, or from the working tree
15       and the index. git rm will not remove a file from just your working
16       directory. (There is no option to remove a file only from the working
17       tree and yet keep it in the index; use /bin/rm if you want to do that.)
18       The files being removed have to be identical to the tip of the branch,
19       and no updates to their contents can be staged in the index, though
20       that default behavior can be overridden with the -f option. When
21       --cached is given, the staged content has to match either the tip of
22       the branch or the file on disk, allowing the file to be removed from
23       just the index.
24

OPTIONS

26       <pathspec>...
27           Files to remove. A leading directory name (e.g.  dir to remove
28           dir/file1 and dir/file2) can be given to remove all files in the
29           directory, and recursively all sub-directories, but this requires
30           the -r option to be explicitly given.
31
32           The command removes only the paths that are known to Git.
33
34           File globbing matches across directory boundaries. Thus, given two
35           directories d and d2, there is a difference between using git rm
36           'd*' and git rm 'd/*', as the former will also remove all of
37           directory d2.
38
39           For more details, see the pathspec entry in gitglossary(7).
40
41       -f, --force
42           Override the up-to-date check.
43
44       -n, --dry-run
45           Don’t actually remove any file(s). Instead, just show if they exist
46           in the index and would otherwise be removed by the command.
47
48       -r
49           Allow recursive removal when a leading directory name is given.
50
51       --
52           This option can be used to separate command-line options from the
53           list of files, (useful when filenames might be mistaken for
54           command-line options).
55
56       --cached
57           Use this option to unstage and remove paths only from the index.
58           Working tree files, whether modified or not, will be left alone.
59
60       --ignore-unmatch
61           Exit with a zero status even if no files matched.
62
63       -q, --quiet
64           git rm normally outputs one line (in the form of an rm command) for
65           each file removed. This option suppresses that output.
66
67       --pathspec-from-file=<file>
68           Pathspec is passed in <file> instead of commandline args. If <file>
69           is exactly - then standard input is used. Pathspec elements are
70           separated by LF or CR/LF. Pathspec elements can be quoted as
71           explained for the configuration variable core.quotePath (see git-
72           config(1)). See also --pathspec-file-nul and global
73           --literal-pathspecs.
74
75       --pathspec-file-nul
76           Only meaningful with --pathspec-from-file. Pathspec elements are
77           separated with NUL character and all other characters are taken
78           literally (including newlines and quotes).
79

REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM

81       There is no option for git rm to remove from the index only the paths
82       that have disappeared from the filesystem. However, depending on the
83       use case, there are several ways that can be done.
84
85   Using “git commit -a”
86       If you intend that your next commit should record all modifications of
87       tracked files in the working tree and record all removals of files that
88       have been removed from the working tree with rm (as opposed to git rm),
89       use git commit -a, as it will automatically notice and record all
90       removals. You can also have a similar effect without committing by
91       using git add -u.
92
93   Using “git add -A”
94       When accepting a new code drop for a vendor branch, you probably want
95       to record both the removal of paths and additions of new paths as well
96       as modifications of existing paths.
97
98       Typically you would first remove all tracked files from the working
99       tree using this command:
100
101           git ls-files -z | xargs -0 rm -f
102
103       and then untar the new code in the working tree. Alternately you could
104       rsync the changes into the working tree.
105
106       After that, the easiest way to record all removals, additions, and
107       modifications in the working tree is:
108
109           git add -A
110
111       See git-add(1).
112
113   Other ways
114       If all you really want to do is to remove from the index the files that
115       are no longer present in the working tree (perhaps because your working
116       tree is dirty so that you cannot use git commit -a), use the following
117       command:
118
119           git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
120

SUBMODULES

122       Only submodules using a gitfile (which means they were cloned with a
123       Git version 1.7.8 or newer) will be removed from the work tree, as
124       their repository lives inside the .git directory of the superproject.
125       If a submodule (or one of those nested inside it) still uses a .git
126       directory, git rm will move the submodules git directory into the
127       superprojects git directory to protect the submodule’s history. If it
128       exists the submodule.<name> section in the gitmodules(5) file will also
129       be removed and that file will be staged (unless --cached or -n are
130       used).
131
132       A submodule is considered up to date when the HEAD is the same as
133       recorded in the index, no tracked files are modified and no untracked
134       files that aren’t ignored are present in the submodules work tree.
135       Ignored files are deemed expendable and won’t stop a submodule’s work
136       tree from being removed.
137
138       If you only want to remove the local checkout of a submodule from your
139       work tree without committing the removal, use git-submodule(1) deinit
140       instead. Also see gitsubmodules(7) for details on submodule removal.
141

EXAMPLES

143       git rm Documentation/\*.txt
144           Removes all *.txt files from the index that are under the
145           Documentation directory and any of its subdirectories.
146
147           Note that the asterisk * is quoted from the shell in this example;
148           this lets Git, and not the shell, expand the pathnames of files and
149           subdirectories under the Documentation/ directory.
150
151       git rm -f git-*.sh
152           Because this example lets the shell expand the asterisk (i.e. you
153           are listing the files explicitly), it does not remove
154           subdir/git-foo.sh.
155

BUGS

157       Each time a superproject update removes a populated submodule (e.g.
158       when switching between commits before and after the removal) a stale
159       submodule checkout will remain in the old location. Removing the old
160       directory is only safe when it uses a gitfile, as otherwise the history
161       of the submodule will be deleted too. This step will be obsolete when
162       recursive submodule update has been implemented.
163

SEE ALSO

165       git-add(1)
166

GIT

168       Part of the git(1) suite
169
170
171
172Git 2.31.1                        2021-03-26                         GIT-RM(1)
Impressum