如何忽略Git中目录中的文件? [英] How do I ignore files in a directory in Git?

查看:110
本文介绍了如何忽略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会将其视为shell glob模式,并检查与相对于<$ c $的位置相关的路径名的匹配c> .gitignore 文件(如果不是来自 .gitignore 文件,则相对于工作树的顶层)。


  • 否则,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




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 directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (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 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.

  • A leading slash matches the beginning of the pathname. For example, /*.c matches cat-file.c but not mozilla-sha1/sha1.c.

You can find more here

git help gitignore
or
man gitignore

这篇关于如何忽略Git中目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆