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.

https://git-scm.com/docs/gitignore

阅读 2.4k
1 个回答

简单的说,就是当 .gitignore 中配置的路径有 / 开头时,就会从 .gitignore 文件的位置匹配,当没有时,就会在子目录中也匹配。

D:.
├─package-a
│  ├─package-aa
│  │  └─_vendor
│  └─_vendor
└─_vendor
  • .gitignore 无内容下 add

image.png

  • .gitignore 内容为 _vendor 时 add

image.png

  • .gitignore 内容为 /_vendor 时 add

image.png

推荐问题