]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-rm.txt
Start preparing for 1.7.10.1
[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]
01144f20 11'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
d4a1cab5
CW
12
13DESCRIPTION
14-----------
25dc7200 15Remove files from the index, or from the working tree and the index.
441947f6 16`git rm` will not remove a file from just your working directory.
47b70120 17(There is no option to remove a file only from the working tree
25dc7200
JL
18and yet keep it in the index; use `/bin/rm` if you want to do that.)
19The files being removed have to be identical to the tip of the branch,
20and no updates to their contents can be staged in the index,
21though that default behavior can be overridden with the `-f` option.
441947f6 22When `--cached` is given, the staged content has to
25dc7200
JL
23match either the tip of the branch or the file on disk,
24allowing the file to be removed from just the index.
d4a1cab5
CW
25
26
27OPTIONS
28-------
29<file>...::
08d22488 30 Files to remove. Fileglobs (e.g. `*.c`) can be given to
25dc7200
JL
31 remove all matching files. If you want git to expand
32 file glob characters, you may need to shell-escape them.
33 A leading directory name
34 (e.g. `dir` to remove `dir/file1` and `dir/file2`) can be
35 given to remove all files in the directory, and recursively
36 all sub-directories,
37 but this requires the `-r` option to be explicitly given.
d4a1cab5
CW
38
39-f::
01144f20 40--force::
08d22488 41 Override the up-to-date check.
d4a1cab5 42
3240240f
SB
43-n::
44--dry-run::
25dc7200
JL
45 Don't actually remove any file(s). Instead, just show
46 if they exist in the index and would otherwise be removed
47 by the command.
d4a1cab5 48
08d22488
JH
49-r::
50 Allow recursive removal when a leading directory name is
51 given.
d4a1cab5 52
e994004f 53\--::
d4a1cab5
CW
54 This option can be used to separate command-line options from
55 the list of files, (useful when filenames might be mistaken
56 for command-line options).
57
3240240f 58--cached::
25dc7200
JL
59 Use this option to unstage and remove paths only from the index.
60 Working tree files, whether modified or not, will be
61 left alone.
08d22488 62
3240240f 63--ignore-unmatch::
bb1faf0d
SG
64 Exit with a zero status even if no files matched.
65
3240240f
SB
66-q::
67--quiet::
441947f6 68 `git rm` normally outputs one line (in the form of an `rm` command)
b48caa20
SG
69 for each file removed. This option suppresses that output.
70
d4a1cab5
CW
71
72DISCUSSION
73----------
74
25dc7200
JL
75The <file> list given to the command can be exact pathnames,
76file glob patterns, or leading directory names. The command
77removes only the paths that are known to git. Giving the name of
08d22488 78a file that you have not told git about does not remove that file.
d4a1cab5 79
25dc7200
JL
80File globbing matches across directory boundaries. Thus, given
81two directories `d` and `d2`, there is a difference between
438ded45
JN
82using `git rm {apostrophe}d{asterisk}{apostrophe}` and
83`git rm {apostrophe}d/{asterisk}{apostrophe}`, as the former will
25dc7200 84also remove all of directory `d2`.
d4a1cab5 85
47b70120
BG
86REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM
87--------------------------------------------------------
88There is no option for `git rm` to remove from the index only
89the paths that have disappeared from the filesystem. However,
90depending on the use case, there are several ways that can be
91done.
92
f34e9edc
MG
93Using ``git commit -a''
94~~~~~~~~~~~~~~~~~~~~~~~
47b70120
BG
95If you intend that your next commit should record all modifications
96of tracked files in the working tree and record all removals of
97files that have been removed from the working tree with `rm`
98(as opposed to `git rm`), use `git commit -a`, as it will
99automatically notice and record all removals. You can also have a
100similar effect without committing by using `git add -u`.
101
f34e9edc
MG
102Using ``git add -A''
103~~~~~~~~~~~~~~~~~~~~
47b70120
BG
104When accepting a new code drop for a vendor branch, you probably
105want to record both the removal of paths and additions of new paths
106as well as modifications of existing paths.
107
108Typically you would first remove all tracked files from the working
109tree using this command:
110
111----------------
112git ls-files -z | xargs -0 rm -f
113----------------
114
f34e9edc
MG
115and then untar the new code in the working tree. Alternately
116you could 'rsync' the changes into the working tree.
47b70120
BG
117
118After that, the easiest way to record all removals, additions, and
119modifications in the working tree is:
120
121----------------
122git add -A
123----------------
124
125See linkgit:git-add[1].
126
127Other ways
128~~~~~~~~~~
129If all you really want to do is to remove from the index the files
130that are no longer present in the working tree (perhaps because
131your working tree is dirty so that you cannot use `git commit -a`),
132use the following command:
133
134----------------
135git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
136----------------
137
d4a1cab5
CW
138EXAMPLES
139--------
5d2fc913 140`git rm Documentation/\*.txt`::
c300578f 141 Removes all `*.txt` files from the index that are under the
a9877f83 142 `Documentation` directory and any of its subdirectories.
d4a1cab5 143+
c300578f 144Note that the asterisk `*` is quoted from the shell in this
25dc7200
JL
145example; this lets git, and not the shell, expand the pathnames
146of files and subdirectories under the `Documentation/` directory.
d4a1cab5 147
5d2fc913 148`git rm -f git-*.sh`::
a9877f83
JH
149 Because this example lets the shell expand the asterisk
150 (i.e. you are listing the files explicitly), it
08d22488 151 does not remove `subdir/git-foo.sh`.
d4a1cab5 152
56ae8df5 153SEE ALSO
872d001f 154--------
5162e697 155linkgit:git-add[1]
d4a1cab5 156
d4a1cab5
CW
157GIT
158---
9e1f0a85 159Part of the linkgit:git[1] suite