| Nice Find! I added it to my git-themed twitter account here: https://twitter.com/#!/gitHater 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! |