threads / patch / 21880

patch, 2 partsDocumentation: 'git add --all' can remove files

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

## tl;dr

2 messages between Dec 6, 2009 and Dec 6, 2009. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Björn Gustavsson· Dec 6, 2009, 18:07 UTC · lore

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'.

Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
---
 Documentation/git-add.txt |   13 +++++++++----
 Documentation/git-rm.txt  |    4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)
Show changes to 2 files +13 −4

Documentation/git-add.txt, Documentation/git-rm.txt

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index e93e606..b7e8aa2 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -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::
diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt
index 5afb1e7..b4dff5b 100644
--- a/Documentation/git-rm.txt
+++ b/Documentation/git-rm.txt
@@ -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::
-- 
1.6.6.rc1.31.g1a56b
Junio C Hamano· Dec 6, 2009, 21:14 UTC · re: Björn Gustavsson · lore

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

Björn Gustavsson <bgustavsson@gmail.com> writes:
Show 10 quoted lines
> diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
> index e93e606..b7e8aa2 100644
> --- a/Documentation/git-add.txt
> +++ b/Documentation/git-add.txt
> @@ -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.
> ++
> +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.

Show 11 quoted lines
> diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt
> index 5afb1e7..b4dff5b 100644
> --- a/Documentation/git-rm.txt
> +++ b/Documentation/git-rm.txt
> @@ -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.

← back to recent threads