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

前端 未结 4 654
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  借酒劲吻你
    2020-12-16 23:34

    Note that the right syntax should be git rm -r . ('dot')

    More worrying is git rm -r (empty pathspec string) which does the same until Git 2.11!

    See commit d426430 (22 Jun 2016) by Emily Xie (emilyxxie).
    (Merged by Junio C Hamano -- gitster -- in commit 3b1e135, 26 Oct 2016)

    pathspec: warn on empty strings as pathspec

    An empty string as a pathspec element matches all paths.
    A buggy script, however, could accidentally assign an empty string to a variable that then gets passed to a Git command invocation, e.g.:

    path=... compute a path to be removed in $path ...
    git rm -r "$paht"
    

    which would unintentionally remove all paths in the current directory.

    The fix for this issue requires a two-step approach.

    • As there may be existing scripts that knowingly use empty strings in this manner, the first step simply gives a warning that (1) tells that an empty string will become an invalid pathspec element and (2) asks the user to use "." if they mean to match all.

    • For step two, a follow-up patch several release cycles later will remove the warning and throw an error instead.


    Update for Git 2.15.x/2.16 (Q1 2018):

    The message "will be made invalid in upcoming releases" disappear, and becomes:

    empty string is not a valid pathspec.
    please use . instead if you meant to match all paths
    

    See commit 9e4e8a6 (07 Jun 2017) by Emily Xie (emilyxxie).
    See commit 229a95a (23 Jun 2017) by Junio C Hamano (gitster).
    (Merged by Junio C Hamano -- gitster -- in commit 728c573, 06 Nov 2017)

    An empty string as a pathspec element matches all paths.
    A buggy script, however, could accidentally assign an empty string to a variable that then gets passed to a Git command invocation, e.g.:

    path=... compute a path to be removed in $path ...
    git rm -r "$path"
    

    which would unintentionally remove all paths in the current directory.

提交回复
热议问题