blob: 5d31860eb1ddf57251d61d16b34693cebc4fd297 [file] [log] [blame]
Carl Worthd4a1cab2006-02-21 15:04:51 -08001git-rm(1)
2=========
3
4NAME
5----
Fredrik Kuivinen7bd7f282006-03-09 17:24:50 +01006git-rm - Remove files from the working tree and from the index
Carl Worthd4a1cab2006-02-21 15:04:51 -08007
8SYNOPSIS
9--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040010[verse]
Pieter de Bie01144f22008-08-09 00:37:02 +020011'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
Carl Worthd4a1cab2006-02-21 15:04:51 -080012
13DESCRIPTION
14-----------
Jon Loeliger25dc7202008-04-16 18:41:27 -050015Remove files from the index, or from the working tree and the index.
Björn Gustavsson441947f2009-12-07 19:26:57 +010016`git rm` will not remove a file from just your working directory.
Björn Gustavsson47b70122009-12-07 19:35:42 +010017(There is no option to remove a file only from the working tree
Jon Loeliger25dc7202008-04-16 18:41:27 -050018and 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.
Björn Gustavsson441947f2009-12-07 19:26:57 +010022When `--cached` is given, the staged content has to
Jon Loeliger25dc7202008-04-16 18:41:27 -050023match either the tip of the branch or the file on disk,
24allowing the file to be removed from just the index.
Carl Worthd4a1cab2006-02-21 15:04:51 -080025
26
27OPTIONS
28-------
29<file>...::
Junio C Hamano08d22482006-12-25 03:23:45 -080030 Files to remove. Fileglobs (e.g. `*.c`) can be given to
Jon Loeliger25dc7202008-04-16 18:41:27 -050031 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.
Carl Worthd4a1cab2006-02-21 15:04:51 -080038
39-f::
Pieter de Bie01144f22008-08-09 00:37:02 +020040--force::
Junio C Hamano08d22482006-12-25 03:23:45 -080041 Override the up-to-date check.
Carl Worthd4a1cab2006-02-21 15:04:51 -080042
Stephan Beyer32402402008-06-08 03:36:09 +020043-n::
44--dry-run::
Jon Loeliger25dc7202008-04-16 18:41:27 -050045 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.
Carl Worthd4a1cab2006-02-21 15:04:51 -080048
Junio C Hamano08d22482006-12-25 03:23:45 -080049-r::
50 Allow recursive removal when a leading directory name is
51 given.
Carl Worthd4a1cab2006-02-21 15:04:51 -080052
seane9940042006-05-05 15:05:24 -040053\--::
Carl Worthd4a1cab2006-02-21 15:04:51 -080054 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
Stephan Beyer32402402008-06-08 03:36:09 +020058--cached::
Jon Loeliger25dc7202008-04-16 18:41:27 -050059 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.
Junio C Hamano08d22482006-12-25 03:23:45 -080062
Stephan Beyer32402402008-06-08 03:36:09 +020063--ignore-unmatch::
Steven Grimmbb1faf02007-04-16 00:53:24 -070064 Exit with a zero status even if no files matched.
65
Stephan Beyer32402402008-06-08 03:36:09 +020066-q::
67--quiet::
Björn Gustavsson441947f2009-12-07 19:26:57 +010068 `git rm` normally outputs one line (in the form of an `rm` command)
Steven Grimmb48caa22007-04-16 00:46:48 -070069 for each file removed. This option suppresses that output.
70
Carl Worthd4a1cab2006-02-21 15:04:51 -080071
72DISCUSSION
73----------
74
Jon Loeliger25dc7202008-04-16 18:41:27 -050075The <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
Junio C Hamano08d22482006-12-25 03:23:45 -080078a file that you have not told git about does not remove that file.
Carl Worthd4a1cab2006-02-21 15:04:51 -080079
Jon Loeliger25dc7202008-04-16 18:41:27 -050080File globbing matches across directory boundaries. Thus, given
81two directories `d` and `d2`, there is a difference between
Jeff King6cf378f2012-04-26 04:51:57 -040082using `git rm 'd*'` and `git rm 'd/*'`, as the former will
Jon Loeliger25dc7202008-04-16 18:41:27 -050083also remove all of directory `d2`.
Carl Worthd4a1cab2006-02-21 15:04:51 -080084
Björn Gustavsson47b70122009-12-07 19:35:42 +010085REMOVING 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
Michael J Gruberf34e9ed2010-12-07 10:07:11 +010092Using ``git commit -a''
93~~~~~~~~~~~~~~~~~~~~~~~
Björn Gustavsson47b70122009-12-07 19:35:42 +010094If 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
Michael J Gruberf34e9ed2010-12-07 10:07:11 +0100101Using ``git add -A''
102~~~~~~~~~~~~~~~~~~~~
Björn Gustavsson47b70122009-12-07 19:35:42 +0100103When 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
110----------------
111git ls-files -z | xargs -0 rm -f
112----------------
113
Michael J Gruberf34e9ed2010-12-07 10:07:11 +0100114and then untar the new code in the working tree. Alternately
115you could 'rsync' the changes into the working tree.
Björn Gustavsson47b70122009-12-07 19:35:42 +0100116
117After that, the easiest way to record all removals, additions, and
118modifications in the working tree is:
119
120----------------
121git add -A
122----------------
123
124See linkgit:git-add[1].
125
126Other ways
127~~~~~~~~~~
128If all you really want to do is to remove from the index the files
129that are no longer present in the working tree (perhaps because
130your working tree is dirty so that you cannot use `git commit -a`),
131use the following command:
132
133----------------
134git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
135----------------
136
Carl Worthd4a1cab2006-02-21 15:04:51 -0800137EXAMPLES
138--------
Jeff King5d2fc912011-08-03 20:13:29 -0600139`git rm Documentation/\*.txt`::
Jonathan Niederc3005782010-08-20 05:30:24 -0500140 Removes all `*.txt` files from the index that are under the
Junio C Hamanoa9877f82007-01-16 11:50:29 -0800141 `Documentation` directory and any of its subdirectories.
Carl Worthd4a1cab2006-02-21 15:04:51 -0800142+
Jonathan Niederc3005782010-08-20 05:30:24 -0500143Note that the asterisk `*` is quoted from the shell in this
Jon Loeliger25dc7202008-04-16 18:41:27 -0500144example; this lets git, and not the shell, expand the pathnames
145of files and subdirectories under the `Documentation/` directory.
Carl Worthd4a1cab2006-02-21 15:04:51 -0800146
Jeff King5d2fc912011-08-03 20:13:29 -0600147`git rm -f git-*.sh`::
Junio C Hamanoa9877f82007-01-16 11:50:29 -0800148 Because this example lets the shell expand the asterisk
149 (i.e. you are listing the files explicitly), it
Junio C Hamano08d22482006-12-25 03:23:45 -0800150 does not remove `subdir/git-foo.sh`.
Carl Worthd4a1cab2006-02-21 15:04:51 -0800151
Junio C Hamano56ae8df2008-05-28 16:55:27 -0700152SEE ALSO
Jeff Muizelaar872d0012006-03-05 16:18:19 -0500153--------
Dan McGee5162e692007-12-29 00:20:38 -0600154linkgit:git-add[1]
Carl Worthd4a1cab2006-02-21 15:04:51 -0800155
Carl Worthd4a1cab2006-02-21 15:04:51 -0800156GIT
157---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200158Part of the linkgit:git[1] suite