Skip to contentSkip to conversation

Documentation: 'git add --all' can remove files

PATCH In review Björn Gustavsson 2 participants 2 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Documentation: 'git add --all' can remove files

Document that 'git add --all' can remove files no longer present in the working tree from the index. Also mention why it is useful, and insert a cross-reference in the 'git rm' documentation to 'git add --all'.

---
 Documentation/git-add.txt |   13 +++++++++----
 Documentation/git-rm.txt  |    4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)
Documentation/git-add.txt +9 -4
index e93e606..b7e8aa2 100644
@@ -16,6 +16,8 @@ DESCRIPTION
 -----------
 This command adds the current content of new or modified files to the
 index, thus staging that content for inclusion in the next commit.
+(Given the `--all` option, the `git add` command will also remove files
+from the index that are no longer present in the working tree.)
 
 The "index" holds a snapshot of the content of the working tree, and it
 is this snapshot that is taken as the contents of the next commit.  Thus
@@ -102,10 +104,13 @@ apply.
 
 -A::
 --all::
-	Update files that git already knows about (same as '\--update')
-	and add all untracked files that are not ignored by '.gitignore'
-	mechanism.
-
+	Update files that git already knows about (same as '\--update'),
+	add all untracked files that are not ignored by '.gitignore'
+	mechanism and remove files from the index that are no longer
+	present in the working tree.
++
+This option is especially useful after running the `rsync` command with
+the working tree as the target to sync the index with the working tree.
 
 -N::
 --intent-to-add::
Documentation/git-rm.txt +4 -0
index 5afb1e7..b4dff5b 100644
@@ -81,6 +81,10 @@ two directories `d` and `d2`, there is a difference between
 using `git rm \'d\*\'` and `git rm \'d/\*\'`, as the former will
 also remove all of directory `d2`.
 
+To automatically remove all files from the index that are no longer
+present in the working tree, see the `--all` option for
+linkgit:git-add[1].
+
 EXAMPLES
 --------
 git rm Documentation/\\*.txt::
Signature · 1 line
1.6.6.rc1.31.g1a56b
#1 lore raw

Documentation/git-add.txt DESCRIPTION · line 20

Quoted 10 lines · Björn Gustavsson
Documentation/git-add.txt +2 -0
index e93e606..b7e8aa2 100644
@@ -16,6 +16,8 @@ DESCRIPTION
 -----------
 This command adds the current content of new or modified files to the
 index, thus staging that content for inclusion in the next commit.
+(Given the `--all` option, the `git add` command will also remove files
+from the index that are no longer present in the working tree.)

The first paragraph says what "git add" does in general (does "something" to the index) and continues to the second paragraph that describes what an index is.

It is a good point that you noticed that the existing description of 'does "something" to the index' covers only the "add as an entirety" and not the whole range of what "git add" can be used for. One thing that is missing is a removal, and "-A" is one of the two options that lets you do so.

But "-u" is to match the index with the work tree contents (it does not add untracked-so-far paths). At least, "Given the --all option," part needs to be rethought.

More importantly, 'does "something" to the index' is not limited to the "add whole" and "remove path". Perhaps we would want to update the first paragraph like this to cover partial add while we are at it.

This command updates the index using the current content found in the work tree, to prepare the content staged for the next commit. It typically adds the current content of existing paths as a whole but with some options, it can also be used to add a content with only part of the changes made to the work tree files applied, or remove paths that do not exist in the work tree anymore.

That way we also cover what "add -p" lets you do.

Documentation/git-add.txt apply. · line 113

Quoted 3 lines
Documentation/git-add.txt +3 -0
++
+This option is especially useful after running the `rsync` command with
+the working tree as the target to sync the index with the working tree.

I do not think mentioning rsync like this is helpful; I actually think this clutteres the document and nudges people in a wrong direction at the same time. You usually don't overwrite your source tree you already have under control with rsync. Use cases that do not use "git" as a SCM but as something else do have a valid reason to use rsync, but "git add -A" being useful for that use case is a side effect, and I do not think we should hint people who use "git" as a SCM into that direction, by casually mentioning the use of rsync like the above as if it is a common and encouraged thing to update your work tree from sideways.

Documentation/git-rm.txt two directories `d` and `d2`, there is a difference between · line 86

Quoted 11 lines
Documentation/git-rm.txt +3 -0
index 5afb1e7..b4dff5b 100644
@@ -81,6 +81,10 @@ two directories `d` and `d2`, there is a difference between
 using `git rm \'d\*\'` and `git rm \'d/\*\'`, as the former will
 also remove all of directory `d2`.
 
+To automatically remove all files from the index that are no longer
+present in the working tree, see the `--all` option for
+linkgit:git-add[1].

I think this change is a lot more harmful than being helpful. Many lazy readers would _not_ read "git add --help" but would think "git add -A" would "automatically remove all files from the index that are no longer present". But "add -A" does a lot more than:

    git diff --name-only --diff-filter=D -z | xargs -0 rm -f

So overall I am happy with the issue you identified, but not very happy with the proposed solution.