What pattern does .gitignore follow?

前端 未结 2 1023
梦如初夏
梦如初夏 2021-01-11 11:47

Here is the content of my current directory.

$ ls
foo.foo
$ ls -a
.  ..  .bar.foo  .foo  foo.foo  .gitignore

Then I turn this directory int

2条回答
  •  误落风尘
    2021-01-11 12:35

    gitignore use of '*' follows the glob convention:

    Git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname.

    For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".

    The OP Lone Learner asks in the comments:

    Does the shell also use fnmatch(3) to process glob patterns?
    In that case why does * not match zero characters before. (i.e. hidden files) but gitignore does?

    Because that is a shell configuration choice.

    Type (using shopt, which is specific to bash):

    shopt -s dotglob
    echo *.foo
    .foo foo.foo
    

    That is using dotglob

    If set, Bash includes filenames beginning with a '.' in the results of filename expansion. (for pattern matching)

提交回复
热议问题