Skip to content

Commit 4b68365

Browse files
committed
Merge branch 'bg/maint-add-all-doc' into maint-1.6.5
* bg/maint-add-all-doc: git-rm doc: Describe how to sync index & work tree git-add/rm doc: Consistently back-quote Documentation: 'git add -A' can remove files
2 parents 65d41d4 + 47b7012 commit 4b68365

File tree

2 files changed

+88
-29
lines changed

2 files changed

+88
-29
lines changed

Documentation/git-add.txt

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@ SYNOPSIS
1414

1515
DESCRIPTION
1616
-----------
17-
This command adds the current content of new or modified files to the
18-
index, thus staging that content for inclusion in the next commit.
17+
This command updates the index using the current content found in
18+
the working tree, to prepare the content staged for the next commit.
19+
It typically adds the current content of existing paths as a whole,
20+
but with some options it can also be used to add content with
21+
only part of the changes made to the working tree files applied, or
22+
remove paths that do not exist in the working tree anymore.
1923

2024
The "index" holds a snapshot of the content of the working tree, and it
2125
is this snapshot that is taken as the contents of the next commit. Thus
2226
after making any changes to the working directory, and before running
23-
the commit command, you must use the 'add' command to add any new or
27+
the commit command, you must use the `add` command to add any new or
2428
modified files to the index.
2529

2630
This command can be performed multiple times before a commit. It only
2731
adds the content of the specified file(s) at the time the add command is
2832
run; if you want subsequent changes included in the next commit, then
29-
you must run 'git add' again to add the new content to the index.
33+
you must run `git add` again to add the new content to the index.
3034

31-
The 'git status' command can be used to obtain a summary of which
35+
The `git status` command can be used to obtain a summary of which
3236
files have changes that are staged for the next commit.
3337

34-
The 'git add' command will not add ignored files by default. If any
35-
ignored files were explicitly specified on the command line, 'git add'
38+
The `git add` command will not add ignored files by default. If any
39+
ignored files were explicitly specified on the command line, `git add`
3640
will fail with a list of ignored files. Ignored files reached by
3741
directory recursion or filename globbing performed by Git (quote your
38-
globs before the shell) will be silently ignored. The 'add' command can
42+
globs before the shell) will be silently ignored. The `add` command can
3943
be used to add ignored files with the `-f` (force) option.
4044

4145
Please see linkgit:git-commit[1] for alternative ways to add content to a
@@ -92,28 +96,31 @@ apply.
9296

9397
-u::
9498
--update::
95-
Update only files that git already knows about, staging modified
96-
content for commit and marking deleted files for removal. This
97-
is similar
98-
to what "git commit -a" does in preparation for making a commit,
99-
except that the update is limited to paths specified on the
100-
command line. If no paths are specified, all tracked files in the
101-
current directory and its subdirectories are updated.
99+
Only match <filepattern> against already tracked files in
100+
the index rather than the working tree. That means that it
101+
will never stage new files, but that it will stage modified
102+
new contents of tracked files and that it will remove files
103+
from the index if the corresponding files in the working tree
104+
have been removed.
105+
+
106+
If no <filepattern> is given, default to "."; in other words,
107+
update all tracked files in the current directory and its
108+
subdirectories.
102109

103110
-A::
104111
--all::
105-
Update files that git already knows about (same as '\--update')
106-
and add all untracked files that are not ignored by '.gitignore'
107-
mechanism.
108-
112+
Like `-u`, but match <filepattern> against files in the
113+
working tree in addition to the index. That means that it
114+
will find new files as well as staging modified content and
115+
removing files that are no longer in the working tree.
109116

110117
-N::
111118
--intent-to-add::
112119
Record only the fact that the path will be added later. An entry
113120
for the path is placed in the index with no content. This is
114121
useful for, among other things, showing the unstaged content of
115-
such files with 'git diff' and committing them with 'git commit
116-
-a'.
122+
such files with `git diff` and committing them with `git commit
123+
-a`.
117124

118125
--refresh::
119126
Don't add the file(s), but only refresh their stat()
@@ -133,7 +140,7 @@ apply.
133140
Configuration
134141
-------------
135142

136-
The optional configuration variable 'core.excludesfile' indicates a path to a
143+
The optional configuration variable `core.excludesfile` indicates a path to a
137144
file containing patterns of file names to exclude from git-add, similar to
138145
$GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
139146
those in info/exclude. See linkgit:gitrepository-layout[5].
@@ -181,17 +188,17 @@ and type return, like this:
181188
What now> 1
182189
------------
183190

184-
You also could say "s" or "sta" or "status" above as long as the
191+
You also could say `s` or `sta` or `status` above as long as the
185192
choice is unique.
186193

187194
The main command loop has 6 subcommands (plus help and quit).
188195

189196
status::
190197

191198
This shows the change between HEAD and index (i.e. what will be
192-
committed if you say "git commit"), and between index and
199+
committed if you say `git commit`), and between index and
193200
working tree files (i.e. what you could stage further before
194-
"git commit" using "git-add") for each path. A sample output
201+
`git commit` using `git add`) for each path. A sample output
195202
looks like this:
196203
+
197204
------------

Documentation/git-rm.txt

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ SYNOPSIS
1212
DESCRIPTION
1313
-----------
1414
Remove files from the index, or from the working tree and the index.
15-
'git-rm' will not remove a file from just your working directory.
16-
(There is no option to remove a file only from the work tree
15+
`git rm` will not remove a file from just your working directory.
16+
(There is no option to remove a file only from the working tree
1717
and yet keep it in the index; use `/bin/rm` if you want to do that.)
1818
The files being removed have to be identical to the tip of the branch,
1919
and no updates to their contents can be staged in the index,
2020
though that default behavior can be overridden with the `-f` option.
21-
When '--cached' is given, the staged content has to
21+
When `--cached` is given, the staged content has to
2222
match either the tip of the branch or the file on disk,
2323
allowing the file to be removed from just the index.
2424

@@ -64,7 +64,7 @@ OPTIONS
6464

6565
-q::
6666
--quiet::
67-
'git-rm' normally outputs one line (in the form of an "rm" command)
67+
`git rm` normally outputs one line (in the form of an `rm` command)
6868
for each file removed. This option suppresses that output.
6969

7070

@@ -81,6 +81,58 @@ two directories `d` and `d2`, there is a difference between
8181
using `git rm \'d\*\'` and `git rm \'d/\*\'`, as the former will
8282
also remove all of directory `d2`.
8383

84+
REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM
85+
--------------------------------------------------------
86+
There is no option for `git rm` to remove from the index only
87+
the paths that have disappeared from the filesystem. However,
88+
depending on the use case, there are several ways that can be
89+
done.
90+
91+
Using "git commit -a"
92+
~~~~~~~~~~~~~~~~~~~~~
93+
If you intend that your next commit should record all modifications
94+
of tracked files in the working tree and record all removals of
95+
files that have been removed from the working tree with `rm`
96+
(as opposed to `git rm`), use `git commit -a`, as it will
97+
automatically notice and record all removals. You can also have a
98+
similar effect without committing by using `git add -u`.
99+
100+
Using "git add -A"
101+
~~~~~~~~~~~~~~~~~~
102+
When accepting a new code drop for a vendor branch, you probably
103+
want to record both the removal of paths and additions of new paths
104+
as well as modifications of existing paths.
105+
106+
Typically you would first remove all tracked files from the working
107+
tree using this command:
108+
109+
----------------
110+
git ls-files -z | xargs -0 rm -f
111+
----------------
112+
113+
and then "untar" the new code in the working tree. Alternately
114+
you could "rsync" the changes into the working tree.
115+
116+
After that, the easiest way to record all removals, additions, and
117+
modifications in the working tree is:
118+
119+
----------------
120+
git add -A
121+
----------------
122+
123+
See linkgit:git-add[1].
124+
125+
Other ways
126+
~~~~~~~~~~
127+
If all you really want to do is to remove from the index the files
128+
that are no longer present in the working tree (perhaps because
129+
your working tree is dirty so that you cannot use `git commit -a`),
130+
use the following command:
131+
132+
----------------
133+
git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
134+
----------------
135+
84136
EXAMPLES
85137
--------
86138
git rm Documentation/\\*.txt::

0 commit comments

Comments
 (0)