tags:

views:

1329

answers:

3

I have several .screen files inside /xxx/documentation and its subdirectories that are already tracked by Git.

After modifying many of these screen files, I run git add documentation/\\*.screen—as indicated by the first example in git-add's documentation—to stage these files, but the command fails:

fatal: pathspec 'documentation/\*.screen' did not match any files

Is my command bad, or does git have a bug?

A: 

try

git add ./documentation/*.screen
kubi
Isn't it the command only add file from ./documentation, not from its sub-directories?
Phương Nguyễn
You're right. I just tried your original command on my machine and it worked fine, though.
kubi
+2  A: 

You told the shell to look for *.screen (i.e. exactly this string - which doesn't exist - instead of what you want "all files that end with .screen). Omit the \\ so the shell can do the file name expansion for you.

Aaron Digulla
In this manual, they told me to add the double backslashes http://www.kernel.org/pub/software/scm/git/docs/git-add.html.What do you say?
Phương Nguyễn
I've read the example and I understand what they want to do (recursive add) but then, why does the command fail? The error suggest that either there is no file with the extension ".screen" in the directory or that the pattern doesn't get expanded.
Aaron Digulla
Well, that's weird, because when I remove the double back-slashes then the command produce no error.
Phương Nguyễn
+2  A: 

It's a bug in the documentation. Quote the asterisk with

$ git add documentation/\*.screen

or

$ git add 'documentation/*.screen'

to get the behavior you want.

If instead you want to add files in the current directory only, use

$ git add *.screen

UPDATE: I submitted a patch that corrects the issue, now fixed as of version 1.6.6.2.

Greg Bacon
Are these two commands lead to the same result? What about only add files in the current directory but not its sub-directories?
Phương Nguyễn
By the way, kubi mentioned that the command worked fine on his machine, what do you say?
Phương Nguyễn
@Phuong Yes, the two commands lead to the same result. To add files in the current directory only, don't quote the argument, (for example, git add *.screen). I believe kubi and Aaron misunderstood your question because I was surprised to learn (thanks for prompting me!) that git-add has this feature.
Greg Bacon