summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4888c53)
raw | patch | inline | side by side (parent: 4888c53)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 25 Dec 2006 11:13:45 +0000 (03:13 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 25 Dec 2006 11:29:08 +0000 (03:29 -0800) |
One thing many people found confusing about git-add was that a
file whose name matches an ignored pattern could not be added to
the index. With this, such a file can be added by explicitly
spelling its name to git-add.
Fileglobs and recursive behaviour do not add ignored files to
the index. That is, if a pattern '*.o' is in .gitignore, and
two files foo.o, bar/baz.o are in the working tree:
$ git add foo.o
$ git add '*.o'
$ git add bar
Only the first form adds foo.o to the index.
Signed-off-by: Junio C Hamano <junkio@cox.net>
file whose name matches an ignored pattern could not be added to
the index. With this, such a file can be added by explicitly
spelling its name to git-add.
Fileglobs and recursive behaviour do not add ignored files to
the index. That is, if a pattern '*.o' is in .gitignore, and
two files foo.o, bar/baz.o are in the working tree:
$ git add foo.o
$ git add '*.o'
$ git add bar
Only the first form adds foo.o to the index.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-add.txt | patch | blob | history | |
builtin-add.c | patch | blob | history |
index 8710b3a75e0bfb7d0643a25ee7b9548ea5b01261..2fef0681bfaf2155d667798eeb7d450fd1ccfcd8 100644 (file)
The 'git status' command can be used to obtain a summary of what is included
for the next commit.
-This command only adds non-ignored files, to add ignored files use
-"git update-index --add".
+This command can be used to add ignored files, but they have to be
+explicitly and exactly specified from the command line. File globbing
+and recursive behaviour do not add ignored files.
Please see gitlink:git-commit[1] for alternative ways to add content to a
commit.
OPTIONS
-------
<file>...::
- Files to add content from.
+ Files to add content from. Fileglobs (e.g. `*.c`) can
+ be given to add all matching files. Also a
+ leading directory name (e.g. `dir` to add `dir/file1`
+ and `dir/file2`) can be given to add all files in the
+ directory, recursively.
-n::
Don't actually add the file(s), just show if they exist.
diff --git a/builtin-add.c b/builtin-add.c
index 17641b433d5249a88a396fa4d68415f1d1dcd7ca..822075ac22beb2b11ee43f84718df71428a67921 100644 (file)
--- a/builtin-add.c
+++ b/builtin-add.c
i = dir->nr;
while (--i >= 0) {
struct dir_entry *entry = *src++;
- if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) {
+ int how = match_pathspec(pathspec, entry->name, entry->len,
+ prefix, seen);
+ /*
+ * ignored entries can be added with exact match,
+ * but not with glob nor recursive.
+ */
+ if (!how ||
+ (entry->ignored_entry && how != MATCHED_EXACTLY)) {
free(entry);
continue;
}
/* Set up the default git porcelain excludes */
memset(dir, 0, sizeof(*dir));
+ if (pathspec)
+ dir->show_both = 1;
dir->exclude_per_dir = ".gitignore";
path = git_path("info/exclude");
if (!access(path, R_OK))