如何忽略Git中目录中的文件? [英] How do I ignore files in a directory in Git?
问题描述
.gitignore
文件忽略目录中的文件的正确语法是什么?
是
config / databases.yml
cache / *
log / *
data / sql / *
lib / filter / base / *
lib / form / base / *
lib / model / map / * $ b $ lib / model / om / *
或
/config/databases.yml
/ cache / *
/ log / *
/ data / sql / *
/ lib / filter / base / *
/ lib / form / base / *
/ lib / model / map / *
/ lib / model / om / *
?
图案格式
b$ b
-
空白行不匹配任何文件,因此它可以作为可读性的分隔符。
-
以
#
开头的行用作注释。 可选的前缀!
,否定模式;任何先前模式排除的匹配文件将再次包含在内。如果否定模式匹配,则这将覆盖较低优先模式的源。 -
如果模式以斜线结尾,则为了以下描述,但它只会找到与目录匹配的内容。换句话说,
foo /
会匹配目录foo
及其下的路径,但不会匹配常规文件或一个符号链接foo
(这与pathpec在git中的工作方式一致)。 -
否则,git会将该模式视为一个适用于
fnmatch(3)
与FNM_PATHNAME
标记:模式中的通配符与路径名中的/
不匹配。例如,Documentation / *。html
匹配Documentation / git.html
但不是Documentation / ppc / ppc.html
或tools / perf / Documentation / perf.html
。 -
前导斜杠匹配路径名的开头。例如,
/ *。c
匹配cat-file.c
但不是mozilla-sha1 /sha1.c
。
>如果模式不包含斜线 /
,git会将其视为shell glob模式,并检查与相对于<$ c $的位置相关的路径名的匹配c> .gitignore 文件(如果不是来自 .gitignore
文件,则相对于工作树的顶层)。
h1>
git help gitignore
或
man gitignore
What is the proper syntax for the .gitignore
file to ignore files in a directory?
Would it be
config/databases.yml
cache/*
log/*
data/sql/*
lib/filter/base/*
lib/form/base/*
lib/model/map/*
lib/model/om/*
or
/config/databases.yml
/cache/*
/log/*
/data/sql/*
/lib/filter/base/*
/lib/form/base/*
/lib/model/map/*
/lib/model/om/*
?
PATTERN FORMAT
A blank line matches no files, so it can serve as a separator for readability.
A line starting with
#
serves as a comment.An optional prefix
!
which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words,
foo/
will match a directoryfoo
and paths underneath it, but will not match a regular file or a symbolic linkfoo
(this is consistent with the way how pathspec works in general in git).If the pattern does not contain a slash
/
, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the.gitignore
file (relative to the toplevel of the work tree if not from a.gitignore
file).Otherwise, git treats the pattern as a shell glob suitable for consumption by
fnmatch(3)
with theFNM_PATHNAME
flag: wildcards in the pattern will not match a/
in the pathname. For example,Documentation/*.html
matchesDocumentation/git.html
but notDocumentation/ppc/ppc.html
ortools/perf/Documentation/perf.html
.A leading slash matches the beginning of the pathname. For example,
/*.c
matchescat-file.c
but notmozilla-sha1/sha1.c
.
You can find more here
git help gitignore
or
man gitignore
这篇关于如何忽略Git中目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!