若要忽略文件以包含在 Cursor 功能中,例如代码库索引编制,你可以在项目根目录中使用一个 .cursorignore 文件。它的工作方式与 .gitignore 适用于 git 的方式相同。

.cursorignore 尊重 .gitignore。如果你已经有了 .gitignore,则默认情况下将忽略这些文件。如果你想忽略其他文件,可以将它们添加到 .cursorignore 文件中。

.cursorignore 文件示例

忽略特定文件

# Ignore all files in the `dist` directory
dist/

# Ignore all `.log` files
*.log

# Ignore specific file `config.json`
config.json

仅包含特定文件

仅包含 app 目录中的 *.py 文件。请注意,这是与 .gitignore 相同的语法。

# ignore everything
*
# do not ignore app
!app/
# do not ignore directories inside app
!app/*/
!app/**/*/
# don't ignore python files
!*.py

故障排除

忽略文件语法有时会令人困惑。.cursorignore 文件遵循与 .gitignore 完全相同的语法,因此,如果你尝试使用一个忽略文件,而它没有按照你预期的方式工作,我们建议针对此问题进行谷歌搜索,在搜索查询中将 cursorignore 替换为 gitignore。可能有其他人遇到过相同的问题,StackOverflow 会有一个不错的答案。

一个常见的示例:如何忽略除了具有 .php 扩展名之外的所有文件(仅添加 * 后跟 !*.php 不起作用,因为 gitignore 文件发现器不会深入其中发现子目录中的任何 .php 文件)。