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] [--quiet]
10       [--] <file>...
11

DESCRIPTION

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

OPTIONS

24       <file>...
25           Files to remove. Fileglobs (e.g.  *.c) can be given to remove all
26           matching files. If you want git to expand file glob characters, you
27           may need to shell-escape them. A leading directory name (e.g.  dir
28           to remove dir/file1 and dir/file2) can be given to remove all files
29           in the directory, and recursively all sub-directories, but this
30           requires the -r option to be explicitly given.
31
32       -f, --force
33           Override the up-to-date check.
34
35       -n, --dry-run
36           Don’t actually remove any file(s). Instead, just show if they exist
37           in the index and would otherwise be removed by the command.
38
39       -r
40           Allow recursive removal when a leading directory name is given.
41
42       --
43           This option can be used to separate command-line options from the
44           list of files, (useful when filenames might be mistaken for
45           command-line options).
46
47       --cached
48           Use this option to unstage and remove paths only from the index.
49           Working tree files, whether modified or not, will be left alone.
50
51       --ignore-unmatch
52           Exit with a zero status even if no files matched.
53
54       -q, --quiet
55
56           git rm normally outputs one line (in the form of an rm command) for
57           each file removed. This option suppresses that output.
58

DISCUSSION

60       The <file> list given to the command can be exact pathnames, file glob
61       patterns, or leading directory names. The command removes only the
62       paths that are known to git. Giving the name of a file that you have
63       not told git about does not remove that file.
64
65       File globbing matches across directory boundaries. Thus, given two
66       directories d and d2, there is a difference between using git rm 'd*'
67       and git rm 'd/*', as the former will also remove all of directory d2.
68

REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM

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

EXAMPLES

114       git rm Documentation/\*.txt
115           Removes all *.txt files from the index that are under the
116           Documentation directory and any of its subdirectories.
117
118           Note that the asterisk * is quoted from the shell in this example;
119           this lets git, and not the shell, expand the pathnames of files and
120           subdirectories under the Documentation/ directory.
121
122       git rm -f git-*.sh
123           Because this example lets the shell expand the asterisk (i.e. you
124           are listing the files explicitly), it does not remove
125           subdir/git-foo.sh.
126

SEE ALSO

128       git-add(1)
129

AUTHOR

131       Written by Linus Torvalds <torvalds@osdl.org[1]>
132

DOCUMENTATION

134       Documentation by Junio C Hamano and the git-list
135       <git@vger.kernel.org[2]>.
136

GIT

138       Part of the git(1) suite
139

NOTES

141        1. torvalds@osdl.org
142           mailto:torvalds@osdl.org
143
144        2. git@vger.kernel.org
145           mailto:git@vger.kernel.org
146
147
148
149Git 1.7.4.4                       04/11/2011                         GIT-RM(1)
Impressum