What's the difference between git add * and git add ., if any?

时光怂恿深爱的人放手 提交于 2019-11-29 17:31:09

问题


git animals had this series of commands:

git init
git add *
git commit -a -m ‘initial commit and release!’

What does git add * do compared to git add . (which I normally do) are they the same?


回答1:


git add * will add all the paths that are the result of the shell expansion of * whereas git add . will tell git to add the current directory.

git add * won't add paths that begin with a . as the shell expansion of * considers these to be "hidden" paths.

git add * will also fail if any expanded path is currently being ignored by git because git considers it an error if you explicitly specify an ignored path without passing the -f (force) flag to show that you really want to add an ignored path.

If you get git to expand the glob (git add '*') it will add "hidden" files and skip over ignored files. It would work the same as git add . in this case.




回答2:


By default passing a directory to git add will recursively add its sub-directories and files.

The wildcard * will be expanded by your shell as files' names below current directory.

And you know, in Unix . refers only to the current directory, so these two commands are equivalent. Though * is processed by the shell and . is processed by git, they do the same thing.



来源:https://stackoverflow.com/questions/10971221/whats-the-difference-between-git-add-and-git-add-if-any

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!