忽略文件
¥Ignoring Files
本文档概述了 Gemini Ignore (.geminiignore) Gemini CLI 的功能。
¥This document provides an overview of the Gemini Ignore (.geminiignore) feature of the Gemini CLI.
Gemini CLI 具有自动忽略文件的功能,类似于.gitignore(由 Git 使用)和.aiexclude(由 Gemini Code Assist 使用)。将路径添加到您的.geminiignore文件会将它们从支持此功能的工具中排除,尽管它们仍然对其他服务(例如 Git)可见。
¥The Gemini CLI includes the ability to automatically ignore files, similar to .gitignore (used by Git) and .aiexclude (used by Gemini Code Assist). Adding paths to your .geminiignore file will exclude them from tools that support this feature, although they will still be visible to other services (such as Git).
工作原理
¥How it works
当你将路径添加到.geminiignore文件,遵循此文件的工具将从其操作中排除匹配的文件和目录。例如,当您使用read_many_files命令,您的.geminiignore文件将被自动排除。
¥When you add a path to your .geminiignore file, tools that respect this file will exclude matching files and directories from their operations. For example, when you use the read_many_files command, any paths in your .geminiignore file will be automatically excluded.
大多数情况下,.geminiignore遵循惯例.gitignore文件:
¥For the most part, .geminiignore follows the conventions of .gitignore files:
空白行和以...开头的行
#被忽略。¥Blank lines and lines starting with
#are ignored.支持标准 glob 模式(例如
*,?, 和[])。¥Standard glob patterns are supported (such as
*,?, and[]).放一个
/最后只会匹配目录。¥Putting a
/at the end will only match directories.放一个
/一开始就锚定了相对于.geminiignore文件。¥Putting a
/at the beginning anchors the path relative to the.geminiignorefile.!否定一种模式。¥
!negates a pattern.
您可以更新您的.geminiignore随时修改文件。要应用更改,您必须重新启动 Gemini CLI 会话。
¥You can update your .geminiignore file at any time. To apply the changes, you must restart your Gemini CLI session.
如何使用.geminiignore
¥How to use .geminiignore
启用.geminiignore:
¥To enable .geminiignore:
创建名为
.geminiignore位于项目目录的根目录中。¥Create a file named
.geminiignorein the root of your project directory.
将文件或目录添加到.geminiignore:
¥To add a file or directory to .geminiignore:
打开你的
.geminiignore文件。¥Open your
.geminiignorefile.添加您想要忽略的路径或文件,例如:
/archive/或者apikeys.txt。¥Add the path or file you want to ignore, for example:
/archive/orapikeys.txt.
.geminiignore示例
¥.geminiignore examples
您可以使用.geminiignore忽略目录和文件:
¥You can use .geminiignore to ignore directories and files:
# Exclude your /packages/ directory and all subdirectories
/packages/
# Exclude your apikeys.txt file
apikeys.txt
您可以在.geminiignore文件*:
¥You can use wildcards in your .geminiignore file with *:
# Exclude all .md files
*.md
最后,您可以使用以下命令排除文件和目录!:
¥Finally, you can exclude files and directories from exclusion with !:
# Exclude all .md files except README.md
*.md
!README.md
要从您的.geminiignore文件中,删除相关行。
¥To remove paths from your .geminiignore file, delete the relevant lines.