Git忽略忽略太多东西

Git ignore ignoring too many things

我有 foldersrc/folder。我想忽略前者而不是后者,除了 .gitignore 中的 folder 忽略两者。

folder 匹配任何目录中名为 "folder" 的任何文件和目录。在前面加一个斜线:

/folder

这仅与存储库根目录中的目录匹配。

听起来您需要对 .gitignore 文件进行一些小改动:

/folder

这只会忽略根目录中名为 folder 的文件夹。没有 / git 默认情况下将忽略您指定的该文件或文件夹的任何实例。例如,在 macOS 上,通常会在 .gitignore 中看到 .DS_STORE 文件。此单个文件名将在本地 git 存储库中的所有文件夹中匹配。

从 git 文档中阅读有关 .gitignore 的更多信息:https://git-scm.com/docs/gitignore

本次匹配的具体规则:

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.