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