1git-rm(1) 2========= 3 4NAME 5---- 6git-rm - Remove files from the working tree and from the index 7 8SYNOPSIS 9-------- 10[verse] 11'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>... 12 13DESCRIPTION 14----------- 15Remove files from the index, or from the working tree and the index. 16`git rm` will not remove a file from just your working directory. 17(There is no option to remove a file only from the working tree 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. 22When `--cached` is given, the staged content has to 23match either the tip of the branch or the file on disk, 24allowing the file to be removed from just the index. 25 26 27OPTIONS 28------- 29<file>...:: 30 Files to remove. Fileglobs (e.g. `*.c`) can be given to 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. 38 39-f:: 40--force:: 41 Override the up-to-date check. 42 43-n:: 44--dry-run:: 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. 48 49-r:: 50 Allow recursive removal when a leading directory name is 51 given. 52 53\--:: 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 58--cached:: 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. 62 63--ignore-unmatch:: 64 Exit with a zero status even if no files matched. 65 66-q:: 67--quiet:: 68 `git rm` normally outputs one line (in the form of an `rm` command) 69 for each file removed. This option suppresses that output. 70 71 72DISCUSSION 73---------- 74 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 78a file that you have not told git about does not remove that file. 79 80File globbing matches across directory boundaries. Thus, given 81two directories `d` and `d2`, there is a difference between 82using `git rm 'd*'` and `git rm 'd/*'`, as the former will 83also remove all of directory `d2`. 84 85REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM 86-------------------------------------------------------- 87There is no option for `git rm` to remove from the index only 88the paths that have disappeared from the filesystem. However, 89depending on the use case, there are several ways that can be 90done. 91 92Using ``git commit -a'' 93~~~~~~~~~~~~~~~~~~~~~~~ 94If you intend that your next commit should record all modifications 95of tracked files in the working tree and record all removals of 96files that have been removed from the working tree with `rm` 97(as opposed to `git rm`), use `git commit -a`, as it will 98automatically notice and record all removals. You can also have a 99similar effect without committing by using `git add -u`. 100 101Using ``git add -A'' 102~~~~~~~~~~~~~~~~~~~~ 103When accepting a new code drop for a vendor branch, you probably 104want to record both the removal of paths and additions of new paths 105as well as modifications of existing paths. 106 107Typically you would first remove all tracked files from the working 108tree using this command: 109 110Submodules 111~~~~~~~~~~ 112Only submodules using a gitfile (which means they were cloned 113with a git version 1.7.8 or newer) will be removed from the work 114tree, as their repository lives inside the .git directory of the 115superproject. If a submodule (or one of those nested inside it) 116still uses a .git directory, `git rm` will fail - no matter if forced 117or not - to protect the submodule's history. 118 119A submodule is considered up-to-date when the HEAD is the same as 120recorded in the index, no tracked files are modified and no untracked 121files that aren't ignored are present in the submodules work tree. 122Ignored files are deemed expendable and won't stop a submodule's work 123tree from being removed. 124 125---------------- 126git ls-files -z | xargs -0 rm -f 127---------------- 128 129and then untar the new code in the working tree. Alternately 130you could 'rsync' the changes into the working tree. 131 132After that, the easiest way to record all removals, additions, and 133modifications in the working tree is: 134 135---------------- 136git add -A 137---------------- 138 139See linkgit:git-add[1]. 140 141Other ways 142~~~~~~~~~~ 143If all you really want to do is to remove from the index the files 144that are no longer present in the working tree (perhaps because 145your working tree is dirty so that you cannot use `git commit -a`), 146use the following command: 147 148---------------- 149git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached 150---------------- 151 152EXAMPLES 153-------- 154`git rm Documentation/\*.txt`:: 155 Removes all `*.txt` files from the index that are under the 156 `Documentation` directory and any of its subdirectories. 157+ 158Note that the asterisk `*` is quoted from the shell in this 159example; this lets git, and not the shell, expand the pathnames 160of files and subdirectories under the `Documentation/` directory. 161 162`git rm -f git-*.sh`:: 163 Because this example lets the shell expand the asterisk 164 (i.e. you are listing the files explicitly), it 165 does not remove `subdir/git-foo.sh`. 166 167SEE ALSO 168-------- 169linkgit:git-add[1] 170 171GIT 172--- 173Part of the linkgit:git[1] suite