Let me explain what's happening.
What you are looking at is actually part-git, part unix-shell-y.
You did ls * .txt
Let's try something way crazy, type echo * .txt
What do you see? All of your txt files right? But that's just echo, not ls.
Ahh. Here's the clinch. When you do " * ", that's called either shell "expansion" or "globbing" depending on your shell. Basically, the shell says "ok, before I run your command, I'm going to look at it and see if I need to do anything on my end"
This is why you can do
$ n=0
$ echo $n
The shell hijacks your input, replacing "$n" with "0", then feeds it into echoIn your example, the shell has hijacked the star in "ls * .txt", replaced it with all of your txt files, say (a.txt, b.txt) and then ran ls.
That means that ls ACTUALLY got
ls a.txt b.txt
And THAT's why it works with echo.---------
So git add "* .txt" works differently, what gives?
Well, when you put things in double or single quotes you are telling the shell "hey, don't do your usual stuff here". The single quotes are more extreme. If we go back to our n=0 example we can try two more things:
$ n=0
$ echo $n
$ echo "$n"
$ echo '$n'
As you can see, the ' says "relax shell, I have this".So when you do
git add "* .txt"
you are actually passing the "* .txt" to git.In most reasonable, sensible programs, the program will look for a file named "asterisk dot t x t" in this case.
But alas, our friends at git have decided to be tricky. The ' * ' syntax for git is similar to gitignore-like syntax (http://www.kernel.org/pub/software/scm/git/docs/v1.7.10/giti...)
"Awesome", you exclaim! Not so fast. It's not the same.
So git add '!1' doesn't work. git add 'one/ * * ' doesn't work, only git add ' * ' seems to work.
Why is it so hard? Good question! I haven't any idea. But we can commiserate together ... you know, over twitter.
Have a good one!
I wouldn't think this is so much an error as they _want_ you to use '*.txt' to add the files in the subdirectory along with the files in the root. They could have touched better on the difference between quotes and no quotes though.
but when you put quotes around "* .txt", that tells bash not to expand the glob.
so in the above case, '* .txt' is actually getting passed into git, rather than 'foo.txt bar.txt dog.txt' etc. I'm not a git user, but it sounds like git has special handling for "* .txt" which causes it to perform its own glob expansion, which happens to also include descending into directories. hilarity ensues.
EDIT: I can't seem to figure out how to type * .txt without triggering the italicized formatter, so I had to put a space after the asterisk. urgh.
EDIT: I'm wrong. Using quotation marks DOES make git fetch .txt files within subdirectories. As pointed out by cellularmitosis, git seems to do it's own "interesting" glob expansion.