grgit-add
Synopsis
grgit.add(patterns: ['<path>', ...], update: <boolean>)
grgit.add {
patterns = ['<path>', ...]
update = <boolean>
}
Description
This command updates the index using the current content found in the working 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 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 is this snapshot that is taken as the contents of the next commit. Thus after making any changes to the working tree, and before running the commit command, you must use the add command to add any new or modified files to the index.
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 run; if you want subsequent changes included in the next commit, then you must run add
again to add the new content to the index.
The grgit-status command can be used to obtain a summary of which files have changes that are staged for the next commit.
Please see grgit-commit for alternative ways to add content to a commit.
Options
- patterns
-
(
Set<String>
, default[]
) Files to add content from. A leading directory name (e.g.dir
to adddir/file1
anddir/file2
) can be given to update the index to match the current state of the directory as a whole (e.g. specifyingdir
will record not just a filedir/file1
modified in the working tree, a filedir/file2
added to the working tree, but also a filedir/file3
removed from the working tree. - update
-
(
boolean
, defaultfalse
) Update the index just where it already has an entry matchingpatterns
. This removes as well as modifies index entries to match the working tree, but adds no new files.If no
pathspec
is given whenupdate
option is used, all tracked files in the entire working tree are updated.
Examples
To add specific files or directories to the path. Wildcards are not supported.
grgit.add(patterns: ['1.txt', 'some/dir'])
To add changes to all currently tracked files.
grgit.add(update: true)