Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: How do I recursively add all files in a directory subtree that match a glob pattern?

Tags:

git

git-add

glob

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?

like image 264
Phương Nguyễn Avatar asked Feb 08 '10 12:02

Phương Nguyễn


People also ask

How do you git add all files in a directory?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

How do I make a directory recursive in git?

So, to recursively add all files or folders and also sub folders to the staging area of git, we can either call “git add -A” or “git add –all”, it will add all files in the project workspace to the staging area, irrespective of location from where this command is executing.

How do I add all Java files to git?

Git Add All Git facilitates us with a unique option of the add command by which we can add all the available files at once. To add all the files from the repository, run the add command with -A option. We can use '. ' Instead of -A option.


2 Answers

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.

like image 73
Greg Bacon Avatar answered Oct 06 '22 02:10

Greg Bacon


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

like image 28
Flueras Bogdan Avatar answered Oct 06 '22 02:10

Flueras Bogdan