Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I git-add with wildcards when ignored files are present?

Tags:

git

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:

  1. Initialize a git repository.
  2. Create a .gitignore with contents:

    *.foo 
  3. Create files "test.txt" and "test.foo".

  4. 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 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?

like image 328
OwenP Avatar asked Apr 06 '10 20:04

OwenP


People also ask

Does git add add ignored files?

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.

How do I use wildcards in Gitignore?

. gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.

How do I track an ignored file in Git?

In order to start tracking previously ignored files or patterns: First, you need to change your working directory to the repository by typing cd <path> . Second, you need to specify the files or patterns to track them by typing git add -f <file name>. extension for a specific file or git add -f *.

How do you add a file to git ignore?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.


2 Answers

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.

like image 189
wRAR Avatar answered Oct 02 '22 15:10

wRAR


Note you can escape more complicated globbing patterns with single quotes as well:

git add '*test*'

will allow git to do its own globbing.

like image 43
Dan Avatar answered Oct 02 '22 14:10

Dan