How do I git-add with wildcards when ignored files are present?
I'm using msysgit on Windows 7 x64. I can't figure out how to tell Git to add a lot of files when there are some files that .gitignore might ignore. For example:
- Initialize a git repository.
Create a .gitignore with contents:
*.foo
Create files "test.txt" and "test.foo".
- Try
git add .
When I try this, git complains that test.foo is ignored and I should use -f if I really want to add it. What I'd rather do is add everything but the files that are configured to be ignored. I looked at the git-add documentation and it looks like -A should help; help says, "... and add all untracked files that are not ignored by .gitignore mechanism." No dice, when I try git add -A .
I get the same error. Using -f adds the ignored file, which is not what I want. (The use case is mass-adding files from a VS project after ignoring .suo 开发者_C百科and other files.)
Is this a problem with the git implementation I'm using, or is there some argument to git-add that I am missing?
Here git add *
complains, but git add .
does what is expected (1.7.0.4, Linux).
From git-add(1)
:
The git add command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files. Ignored files reached by directory recursion or filename globbing performed by Git (quote your globs before the shell) will be silently ignored.
Note you can escape more complicated globbing patterns with single quotes as well:
git add '*test*'
will allow git to do its own globbing.
Another way to do it is to escape the globbing chars, like this:
git add \*
Note that git add --ignore-errors *
would now work, even if some files are ignored.
See commit 1d31e5a by Michael J Gruber (mjg
), Git 2.3.0 (February 2015)
add
: ignore only ignored files"
git add foo bar
" adds neitherfoo
norbar
whenbar
is ignored, but dies to let the user recheck their command invocation.
This becomes less helpful when "git add foo.*
" is subject to shell expansion and some of the expanded files are ignored."
git add --ignore-errors
" is supposed to ignore errors when indexing some files and adds the others. It does ignore errors from actual indexing attempts, but does not ignore the error "file is ignored
" as outlined above. This is unexpected.Change "
git add foo bar
" to addfoo
whenbar
is ignored, but issue a warning and return a failure code as before the change.That is, in the case of trying to add ignored files we now act the same way (with or without "
--ignore-errors
") in which we act for more severe indexing errors when "--ignore-errors
" is specified.
精彩评论