Merge branch 'je/doc-add'

Documentation for "git add" has been updated.

* je/doc-add:
  doc: rephrase the purpose of the staging area
  doc: git-add: simplify discussion of ignored files
  doc: git-add: clarify intro & add an example
This commit is contained in:
Junio C Hamano
2025-09-12 10:41:18 -07:00

View File

@@ -16,18 +16,18 @@ git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [-
DESCRIPTION DESCRIPTION
----------- -----------
This command updates the index using the current content found in Add contents of new or changed files to the index. The "index" (also
the working tree, to prepare the content staged for the next commit. known as the "staging area") is what you use to prepare the contents of
It typically adds the current content of existing paths as a whole, the next commit.
but with some options it can also be used to add content with
only part of the changes made to the working tree files applied, or
remove paths that do not exist in the working tree anymore.
The "index" holds a snapshot of the content of the working tree, and it When you run `git commit` without any other arguments, it will only
is this snapshot that is taken as the contents of the next commit. Thus commit staged changes. For example, if you've edited `file.c` and want
after making any changes to the working tree, and before running to commit your changes to that file, you can run:
the commit command, you must use the `add` command to add any new or
modified files to the index. git add file.c
git commit
You can also add only part of your changes to a file with `git add -p`.
This command can be performed multiple times before a commit. It only This command can be performed multiple times before a commit. It only
adds the content of the specified file(s) at the time the add command is adds the content of the specified file(s) at the time the add command is
@@ -37,12 +37,10 @@ you must run `git add` again to add the new content to the index.
The `git status` command can be used to obtain a summary of which The `git status` command can be used to obtain a summary of which
files have changes that are staged for the next commit. files have changes that are staged for the next commit.
The `git add` command will not add ignored files by default. If any The `git add` command will not add ignored files by default. You can
ignored files were explicitly specified on the command line, `git add` use the `--force` option to add ignored files. If you specify the exact
will fail with a list of ignored files. Ignored files reached by filename of an ignored file, `git add` will fail with a list of ignored
directory recursion or filename globbing performed by Git (quote your files. Otherwise it will silently ignore the file.
globs before the shell) will be silently ignored. The `git add` command can
be used to add ignored files with the `-f` (force) option.
Please see linkgit:git-commit[1] for alternative ways to add content to a Please see linkgit:git-commit[1] for alternative ways to add content to a
commit. commit.