Git add not working with .png files?

前端 未结 5 1171
耶瑟儿~
耶瑟儿~ 2020-12-09 05:44

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

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 06:48

    Michael Mrozek's comment is essentially the answer. *.png matches files of that name in the current directory, not in subdirectories. If you want to add ones in a subdirectory, do so:

    git add src/main/resources/icons/*.png
    

    Or, depending on your shell, you may be able to do:

    git add **/*.png
    

    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.

提交回复
热议问题