git rm * doesn't remove all files in one go

前端 未结 4 658
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 23:23

I was trying out some sample instructions of git and came across this peculiar case that when we do a git rm *, it doesn\'t delete the .* files in

4条回答
  •  猫巷女王i
    2020-12-16 23:35

    The wildcard gets expanded by your shell, and the expansion does not include dot files, by default, in most shells.

    So by the time git executes, the first command has become

    git rm -r folder testfile3
    

    and the second probably a literal

    git rm -r *
    

    which git then expands by itself.

    As remarked by Keith, to remove everything in one go, prevent the shell from expanding the wildcard so that git does the expansion the first time already. This can be done with double or single quotes, or with a backslash before the asterisk. I tend to prefer single quotes:

    git rm -r '*'
    

提交回复
热议问题