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

查看:34
本文介绍了如何忽略 Git 目录中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.gitignore 文件忽略目录中文件的正确语法是什么?

What is the proper syntax for the .gitignore file to ignore files in a directory?

会吗

config/databases.yml
cache/*
log/*
data/sql/*
lib/filter/base/*
lib/form/base/*
lib/model/map/*
lib/model/om/*

/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.

如果模式以斜杠结尾,则出于以下描述的目的将其删除,但它只会找到与目录的匹配项.换句话说,foo/ 将匹配目录 foo 及其下的路径,但不会匹配常规文件或符号链接 foo (这与路径规范在 git 中的一般工作方式一致).

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).

如果模式不包含斜杠 /,git 会将其视为 shell glob 模式,并检查与 .gitignore 位置相关的路径名是否匹配 文件(相对于工作树的顶层,如果不是来自 .gitignore 文件).

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).

否则,git 将模式视为适合 fnmatch(3) 使用的 shell glob,带有 FNM_PATHNAME 标志:模式中的通配符将不匹配路径名中的 /.例如,Documentation/*.html 匹配 Documentation/git.html 但不匹配 Documentation/ppc/ppc.htmltools/perf/Documentation/perf.html.

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.

前导斜杠与路径名的开头匹配.例如,/*.c 匹配 cat-file.c 但不匹配 mozilla-sha1/sha1.c.

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

git help gitignore

man gitignore

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

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