Skip to content

Commit 3ba1f11

Browse files
committed
git-add --all: add all files
People sometimes find that "git add -u && git add ." are 13 keystrokes too many. This reduces it by nine. The support of this has been very low priority for me personally, because I almost never do "git add ." in a directory with already tracked files, and in a new directory, there is no point saying "git add -u". However, for two types of people (that are very different from me), this mode of operation may make sense and there is no reason to leave it unsupported. That is: (1) If you are extremely well disciplined and keep perfect .gitignore, it always is safe to say "git add ."; or (2) If you are extremely undisciplined and do not even know what files you created, and you do not very much care what goes in your history, it does not matter if "git add ." included everything. So there it is, although I suspect I will not use it myself, ever. It will be too much of a change that is against the expectation of the existing users to allow "git commit -a" to include untracked files, and it would be inconsistent if we named this new option "-a", so the short option is "-A". We _might_ want to later add "git commit -A" but that is a separate topic. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c972ec0 commit 3ba1f11

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

builtin-add.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static const char ignore_error[] =
190190
"The following paths are ignored by one of your .gitignore files:\n";
191191

192192
static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
193-
static int ignore_add_errors;
193+
static int ignore_add_errors, addremove;
194194

195195
static struct option builtin_add_options[] = {
196196
OPT__DRY_RUN(&show_only),
@@ -200,6 +200,7 @@ static struct option builtin_add_options[] = {
200200
OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"),
201201
OPT_BOOLEAN('f', "force", &ignored_too, "allow adding otherwise ignored files"),
202202
OPT_BOOLEAN('u', "update", &take_worktree_changes, "update tracked files"),
203+
OPT_BOOLEAN('A', "all", &addremove, "add all, noticing removal of tracked files"),
203204
OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"),
204205
OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, "just skip files which cannot be added because of errors"),
205206
OPT_END(),
@@ -254,6 +255,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
254255

255256
git_config(add_config, NULL);
256257

258+
if (addremove && take_worktree_changes)
259+
die("-A and -u are mutually incompatible");
260+
if (addremove && !argc) {
261+
static const char *here[2] = { ".", NULL };
262+
argc = 1;
263+
argv = here;
264+
}
265+
257266
add_new_files = !take_worktree_changes && !refresh_only;
258267
require_pathspec = !take_worktree_changes;
259268

@@ -286,7 +295,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
286295
goto finish;
287296
}
288297

289-
if (take_worktree_changes)
298+
if (take_worktree_changes || addremove)
290299
exit_status |= add_files_to_cache(prefix, pathspec, flags);
291300

292301
if (add_new_files)

0 commit comments

Comments
 (0)