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
68       `d2.
69

REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM

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

EXAMPLES

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

SEE ALSO

129       git-add(1)
130

AUTHOR

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

DOCUMENTATION

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

GIT

139       Part of the git(1) suite
140

NOTES

142        1. torvalds@osdl.org
143           mailto:torvalds@osdl.org
144
145        2. git@vger.kernel.org
146           mailto:git@vger.kernel.org
147
148
149
150Git 1.7.1                         08/16/2017                         GIT-RM(1)
Impressum