Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"git add *.js" did not add the files in sub-directories

Tags:

git

github

Was trying to commit some changes. I used git add to add any new javascript files that I may have created using the wildcard *.js. Then I committed changes and pushed to github:

git add *.js
git commit -m "stuff"
git push github master

When I checked github, all the files that I had been editing were blank. They were there, just empty.

I then tried to commit again, but GIT said that everything was up to date.

Then I went back and noticed that after I did git commit -m "stuff", GIT displayed a message saying that a bunch of my ".js" files were not staged even though I had just added them using the wildcard: git add *.js. This is the message that was displayed when I attempted to commit.

# On branch master
# Changes not staged for commit:
#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       modified:   src/static/directory1/js/module1/file1.js
#       modified:   src/static/directory1/js/module1/file2.js
#       modified:   src/static/directory1/js/module2/file1.js

In order to fix this I had to go down a few directories when doing my git add:

git add src/static/directory1/*.js

This seemed to worked, because the files were there after I committed again and then pushed to github:

git commit -m "stuff"
git push github master

What was going on here, why did I have to navigate down a few directories to get the wild card to work?

Thanks!

like image 920
Chris Dutrow Avatar asked Aug 15 '12 19:08

Chris Dutrow


People also ask

Does git add Include subfolders?

git add one file that's at the deepest layer of your file structure (the latest level of a Folder you want to add). Then, git add --all :/ . It will add all the Folders , Subfolders and files to the existing repo.

How do you git add all files in a folder?

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 force git to add a file?

The git add command can be used to add ignored files with the -f (force) option. Please see git-commit[1] for alternative ways to add content to a commit.

What is git add * command?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.


2 Answers

even though I had just added them using the wildcard: git add *.js

Shell wildcard expansion does not recurse into subdirectories. The wildcard is expanded before Git gets a chance to see it.

If you use git add '*.js', then Git will see the wildcard and will match it against all path names that end in .js. Because the * is in the initial position, this will end up recursively adding all .js files including in subdirectories.

like image 139
Greg Hewgill Avatar answered Sep 29 '22 16:09

Greg Hewgill


You need to use

git add '*.js'

You have to use quotes so git receives the wildcard before your shell does. If you do not have quotes the shell will only do the wildcard search within your current directory.

like image 37
Aaron Gray Avatar answered Sep 29 '22 16:09

Aaron Gray