Fatal: pathspec 'file.txt' did not match any files, GIT

前端 未结 14 1208
难免孤独
难免孤独 2021-02-04 11:59

I have just started learing GIT. Follow their tutorial.

Now at the very beginning I got stuck with this error:

Fatal: pathspec \'file.txt\' did not match         


        
14条回答
  •  温柔的废话
    2021-02-04 12:00

    Note: you shouldn't see this particular error message in git 1.9/2.0 (Q1 2014).

    See commit 64ed07c by Nguyễn Thái Ngọc Duy (pclouds):

    add: don't complain when adding empty project root

    This behavior was added in 07d7bed (add: don't complain when adding empty project root - 2009-04-28, git 1.6.3.2)
    then broken by 84b8b5d (remove match_pathspec() in favor of match_pathspec_depth() - 2013-07-14, git 1.8.5).

    Reinstate it.


    The idea is:

    We try to warn the user if one of their pathspecs caused no matches, as it may have been a typo. However, we disable the warning if the pathspec points to an existing file, since that means it is not a typo but simply an empty directory.

    Unfortunately, the file_exists() test was broken for one special case: the pathspec of the project root is just "".
    This patch detects this special case and acts as if the file exists (which it must, since it is the project root).

    The user-visible effect is that this:

    $ mkdir repo && cd repo && git init && git add .
    

    used to complain like:

    fatal: pathspec '' did not match any files
    

    but now is a silent no-op.

    It is again a silent no-op in upcoming git 1.9/2.0 (Q1 2014)

提交回复
热议问题