61

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?

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
Phương Nguyễn
  • 8,747
  • 15
  • 62
  • 96
  • The marked answer worked for me, however it should be noted that every wildcard needs to be put in quotes separately, i.e. `git add ' *.cpp *.h'` resulted in the above error `fatal: pathspec ' *.cpp *.h' did not match any files` while `git add ' *.cpp' '*.h'` did its job. – mirtan Jun 15 '18 at 11:12

6 Answers6

61

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
  • 134,834
  • 32
  • 188
  • 245
  • 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 Feb 08 '10 at 16:27
  • By the way, kubi mentioned that the command worked fine on his machine, what do you say? – Phương Nguyễn Feb 08 '10 at 16:36
  • @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 Feb 08 '10 at 16:49
  • @alex I'm curious to know the specifics of your situation that caused it to fail. It sounds like the context is different enough to warrant a separate question that I look forward to reading! – Greg Bacon Jan 14 '12 at 12:08
17

I've tried the accepted answer, but it didn't worked for me.. so here's mine just in case someone wants to get it's job done without spending time in dissecting various aspects that might cause the problem:

find documentation -name "*.screen" | xargs git add -u

//the -u option to git-add adds to index just the files that were previously tracked and modified

Flueras Bogdan
  • 9,187
  • 8
  • 32
  • 30
  • In your case, is `documentation` the name of a directory inside the repo's working tree or a relative path from outside the working tree to the repo's toplevel? – Greg Bacon Jan 14 '12 at 12:11
4

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
  • 321,842
  • 108
  • 597
  • 820
  • 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 Feb 08 '10 at 13:39
  • 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 Feb 08 '10 at 14:13
  • Well, that's weird, because when I remove the double back-slashes then the command produce no error. – Phương Nguyễn Feb 08 '10 at 16:18
4

This what I just used for a similar problem of git adding all the files in a directory:

find . | sed "s/\(.*\)/\"\1\"/g" | xargs git add 

For the original question the command would be:

find -name "*.screen" | sed "s/\(.*\)/\"\1\"/g" | xargs git add 

Note that I'm dealing with the case where a fully specified file name contains spaces. Thats why my answer. Edit the portion before the first | in order to pick out different files to add.

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
3

git add *.java works for me to add recursively all the java files

Jackie
  • 39
  • 1
  • 1
    Wow, it works for me, too! But only if there are no `.java` files in the current directory. If there are, only those files are added. – Robin Green Nov 19 '13 at 19:46
1

try

git add ./documentation/*.screen
kubi
  • 48,104
  • 19
  • 94
  • 118