Add * but sibling is ignored

I made a bunch of updates inside the directory and would like to add them, but they are sitting next to the directory that I have in my .gitignore. Shouldn't git add just ignore so that instead of complaining?

How can I add everything and just skip the ignored thing?

 $ git add assets/* The following paths are ignored by one of your .gitignore files: assets/avatars Use -f if you really want to add them. fatal: no files added 
+5
source share
2 answers

According to the documentation , the flag --ignore-errors simply run the command as you would like.

If some files cannot be added due to errors indexing them, do not interrupt the operation, but continue to add others. The team will still exit with a non-zero status. add.ignoreErrors configuration variable can be set to true to make this the default behavior.

Update:

This does not work in this case, I think, because the assets/* parameter is expanded by the shell, so the actual parameters obtained by git add is an extended list of files and directories, and therefore an obvious error.

I tried this command with good results:

 $ git add assets 

It works even without the --ignore-errors option, because it does not try to add an ignored directory below assets .

+2
source

When you use a wildcard * , it will be expanded by your shell on Unix systems. So running git add assets/* is the equivalent of explicitly adding files below assets/avatars .

For example, if I have two files:

 assets/file1.txt assets/avatars/file2.txt 

Then running git add assets/* expands to:

 git add assets/file1.txt assets/avatars/file2.txt 

So git complains that you are instructing it to add an ignored file. If you want to avoid this message, you can quote * to allow git to make globes. This will give the git command to expand your paths, paying attention to the .gitignore file. For instance:

 git add assets/\* 

In this example, warnings and steps are not generated only the corresponding files, assets/file1.txt .

0
source

All Articles