BrDaHa
BrDaHa

Reputation: 5780

Git won't add certain globs

I'm left scratching my head on this one. So, in git on OSX, you can add files like:

git add *.java

and it will add all files that have the *.java extension. Same for .txt, json, etc. However, when I do a

git add *.xml

nothing happens. It's not specified in my gitignore, so git is reporting it as changed with a git status, but I can't seem to add with the globbing pattern.

I'm not asking HOW to recursively add files by pattern, git, (or bash?) already does that, as explained in my first example.

System:

Upvotes: 3

Views: 751

Answers (2)

Schwern
Schwern

Reputation: 165416

They're nested, so there are some in the root, some in subfolders and so on.

git add *.xml will only add XML files in the current directory. Shell globbing does not include subdirectories. This is a general shell thing.

If you pass a literal glob to git add it will apply it recursively.

git add '*.xml'

This is a feature of git-add. If you want something like this in general you can turn on recursive globbing in bash 4.

git add **/*.xml

Or you can use find and xargs.

find . -name '*.xml' | xargs git add

Upvotes: 0

chepner
chepner

Reputation: 532093

Quote the glob so that it passed to git for processing, rather than expanded by the shell.

git add '*.xml'

Upvotes: 4

Related Questions