I have a dirty working tree, dirty because I made changes to source files and touched up some images. I was trying to add just the images to the index, so I ran this command:
git add *.png
But, this doesn’t add the files. There were a few new image files that were added, but none of the ones that were modified/pre-existing were added.
What gives?
Edit: Here is some relevant terminal output
$ git status
# On branch master
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: src/main/java/net/plugins/analysis/FormMatcher.java
# modified: src/main/resources/icons/doctor_edit_male.png
# modified: src/main/resources/icons/doctor_female.png
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/main/resources/icons/arrow_up.png
# src/main/resources/icons/bullet_arrow_down.png
# src/main/resources/icons/bullet_arrow_up.png
no changes added to commit (use "git add" and/or "git commit -a")
Then executed “git add *.png” (no output after command)
Then:
$ git status
# On branch master
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: src/main/resources/icons/arrow_up.png
# new file: src/main/resources/icons/bullet_arrow_down.png
# new file: src/main/resources/icons/bullet_arrow_up.png
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: src/main/java/net/plugins/analysis/FormMatcher.java
# modified: src/main/resources/icons/doctor_edit_female.png
# modified: src/main/resources/icons/doctor_edit_male.png
Michael Mrozek’s comment is essentially the answer.
*.pngmatches files of that name in the current directory, not in subdirectories. If you want to add ones in a subdirectory, do so:Or, depending on your shell, you may be able to do:
The point is that it’s the shell that does the globbing (expands *.png into a list of filenames). Git has nothing to do with that; it just takes the arguments the shell gives it.
Edit: Since this managed to get accepted, I should go ahead and point out as others did that some git commands do support globbing internally (via fnmatch), so if you quote a glob pattern, it’ll be passed unmodified by the shell to git, where the globbing expansion will take place.