blob: 1d876c2619a414159a121868c5dbaab48e55a708 [file] [log] [blame]
Junio C Hamano34b18112006-02-23 11:21:401git-rm(1)
2=========
3
4NAME
5----
Junio C Hamano01078922006-03-10 00:31:476git-rm - Remove files from the working tree and from the index
Junio C Hamano34b18112006-02-23 11:21:407
8SYNOPSIS
9--------
Junio C Hamano15567bc2011-07-23 00:51:5910[verse]
Junio C Hamanofaa1e502008-08-10 03:55:5811'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
Junio C Hamano34b18112006-02-23 11:21:4012
13DESCRIPTION
14-----------
Junio C Hamano2ec4d362008-04-17 02:17:5315Remove files from the index, or from the working tree and the index.
Junio C Hamanoae05fee2010-01-08 07:39:4616`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
Junio C Hamano2ec4d362008-04-17 02:17:5318and 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.
Junio C Hamanoae05fee2010-01-08 07:39:4622When `--cached` is given, the staged content has to
Junio C Hamano2ec4d362008-04-17 02:17:5323match either the tip of the branch or the file on disk,
24allowing the file to be removed from just the index.
Junio C Hamano34b18112006-02-23 11:21:4025
26
27OPTIONS
28-------
29<file>...::
Junio C Hamano3d2adc72006-12-26 03:21:4530Files to remove. Fileglobs (e.g. `*.c`) can be given to
Junio C Hamano076ffcc2013-02-06 05:13:2131remove all matching files. If you want Git to expand
Junio C Hamano2ec4d362008-04-17 02:17:5332file glob characters, you may need to shell-escape them.
33A leading directory name
34(e.g. `dir` to remove `dir/file1` and `dir/file2`) can be
35given to remove all files in the directory, and recursively
36all sub-directories,
37but this requires the `-r` option to be explicitly given.
Junio C Hamano34b18112006-02-23 11:21:4038
39-f::
Junio C Hamanofaa1e502008-08-10 03:55:5840--force::
Junio C Hamano3d2adc72006-12-26 03:21:4541Override the up-to-date check.
Junio C Hamano34b18112006-02-23 11:21:4042
Junio C Hamanoeb415992008-06-08 22:49:4743-n::
44--dry-run::
Junio C Hamano2ec4d362008-04-17 02:17:5345Don't actually remove any file(s). Instead, just show
46if they exist in the index and would otherwise be removed
47by the command.
Junio C Hamano34b18112006-02-23 11:21:4048
Junio C Hamano3d2adc72006-12-26 03:21:4549-r::
50 Allow recursive removal when a leading directory name is
51 given.
Junio C Hamano34b18112006-02-23 11:21:4052
Junio C Hamano1bb569e2006-05-05 23:14:2553\--::
Junio C Hamano34b18112006-02-23 11:21:4054This option can be used to separate command-line options from
55the list of files, (useful when filenames might be mistaken
56for command-line options).
57
Junio C Hamanoeb415992008-06-08 22:49:4758--cached::
Junio C Hamano2ec4d362008-04-17 02:17:5359Use this option to unstage and remove paths only from the index.
60Working tree files, whether modified or not, will be
61left alone.
Junio C Hamano3d2adc72006-12-26 03:21:4562
Junio C Hamanoeb415992008-06-08 22:49:4763--ignore-unmatch::
Junio C Hamano28cea6a2007-04-18 04:57:1764Exit with a zero status even if no files matched.
65
Junio C Hamanoeb415992008-06-08 22:49:4766-q::
67--quiet::
Junio C Hamanoae05fee2010-01-08 07:39:4668`git rm` normally outputs one line (in the form of an `rm` command)
Junio C Hamano0e3cb532007-04-17 08:28:1169for each file removed. This option suppresses that output.
70
Junio C Hamano34b18112006-02-23 11:21:4071
72DISCUSSION
73----------
74
Junio C Hamano2ec4d362008-04-17 02:17:5375The <file> list given to the command can be exact pathnames,
76file glob patterns, or leading directory names. The command
Junio C Hamano076ffcc2013-02-06 05:13:2177removes 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.
Junio C Hamano34b18112006-02-23 11:21:4079
Junio C Hamano2ec4d362008-04-17 02:17:5380File globbing matches across directory boundaries. Thus, given
81two directories `d` and `d2`, there is a difference between
Junio C Hamanob76a6862012-05-02 22:02:4682using `git rm 'd*'` and `git rm 'd/*'`, as the former will
Junio C Hamano2ec4d362008-04-17 02:17:5383also remove all of directory `d2`.
Junio C Hamano34b18112006-02-23 11:21:4084
Junio C Hamanoae05fee2010-01-08 07:39:4685REMOVING 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
Junio C Hamano28e6d1f2010-12-08 02:06:1492Using ``git commit -a''
93~~~~~~~~~~~~~~~~~~~~~~~
Junio C Hamanoae05fee2010-01-08 07:39:4694If 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
Junio C Hamano28e6d1f2010-12-08 02:06:14101Using ``git add -A''
102~~~~~~~~~~~~~~~~~~~~
Junio C Hamanoae05fee2010-01-08 07:39:46103When 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
Junio C Hamano28e6d1f2010-12-08 02:06:14114and then untar the new code in the working tree. Alternately
115you could 'rsync' the changes into the working tree.
Junio C Hamanoae05fee2010-01-08 07:39:46116
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
Junio C Hamanof2b74942012-11-20 21:06:26137Submodules
138~~~~~~~~~~
139Only submodules using a gitfile (which means they were cloned
Junio C Hamano076ffcc2013-02-06 05:13:21140with a Git version 1.7.8 or newer) will be removed from the work
Junio C Hamanof2b74942012-11-20 21:06:26141tree, as their repository lives inside the .git directory of the
142superproject. If a submodule (or one of those nested inside it)
143still uses a .git directory, `git rm` will fail - no matter if forced
144or not - to protect the submodule's history.
145
146A submodule is considered up-to-date when the HEAD is the same as
147recorded in the index, no tracked files are modified and no untracked
148files that aren't ignored are present in the submodules work tree.
149Ignored files are deemed expendable and won't stop a submodule's work
150tree from being removed.
151
Junio C Hamano240dc3f2013-03-25 23:37:03152If you only want to remove the local checkout of a submodule from your
153work tree without committing the removal,
154use linkgit:git-submodule[1] `deinit` instead.
155
Junio C Hamano34b18112006-02-23 11:21:40156EXAMPLES
157--------
Junio C Hamano16ebcd02011-08-05 00:05:45158`git rm Documentation/\*.txt`::
Junio C Hamano2db3e752010-09-03 21:33:06159Removes all `*.txt` files from the index that are under the
Junio C Hamano1ce39ab2007-01-16 22:05:10160`Documentation` directory and any of its subdirectories.
Junio C Hamano34b18112006-02-23 11:21:40161+
Junio C Hamano2db3e752010-09-03 21:33:06162Note that the asterisk `*` is quoted from the shell in this
Junio C Hamano076ffcc2013-02-06 05:13:21163example; this lets Git, and not the shell, expand the pathnames
Junio C Hamano2ec4d362008-04-17 02:17:53164of files and subdirectories under the `Documentation/` directory.
Junio C Hamano34b18112006-02-23 11:21:40165
Junio C Hamano16ebcd02011-08-05 00:05:45166`git rm -f git-*.sh`::
Junio C Hamano1ce39ab2007-01-16 22:05:10167Because this example lets the shell expand the asterisk
168(i.e. you are listing the files explicitly), it
Junio C Hamano3d2adc72006-12-26 03:21:45169does not remove `subdir/git-foo.sh`.
Junio C Hamano34b18112006-02-23 11:21:40170
Junio C Hamano9049d912008-05-29 02:09:50171SEE ALSO
Junio C Hamano2bb13102006-03-06 07:10:21172--------
Junio C Hamano35738e82008-01-07 07:55:46173linkgit:git-add[1]
Junio C Hamano34b18112006-02-23 11:21:40174
Junio C Hamano34b18112006-02-23 11:21:40175GIT
176---
Junio C Hamanof7c042d2008-06-06 22:50:53177Part of the linkgit:git[1] suite