Dateien von der Verwendung durch Gemini Code Assist ausschließen
Mit Sammlungen den Überblick behalten Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Gemini Code Assist unterstützt das Ausschließen von Dateien aus dem Kontext für die Codegenerierung, Codevervollständigung, Codeumwandlung und Chats. Für Enterprise-Nutzer ist auch die Codeanpassung enthalten.
In vielen Fällen gibt es bestimmte Dateien oder Unterstrukturen, die nicht in Ihrem Kontext enthalten sein sollen.
Sie können diese Dateien mithilfe einer .aiexclude- oder .gitignore-Datei ausschließen.
Einstellungen für Kontextausschlüsse konfigurieren
In diesem Abschnitt erfahren Sie, wie Sie Einstellungen für .aiexclude- und .gitignore-Dateien konfigurieren.
.aiexclude-Datei in die gewünschte Datei ändern
Standardmäßig wird für den Kontextausschluss .aiexclude verwendet. So ändern Sie diese Einstellung in Ihrer IDE:
VS Code
Klicken Sie in der Aktivitätsleiste auf die EinstellungenVerwalten > Einstellungen.
Klicken Sie im Fenster Einstellungen auf Erweiterungen > Gemini Code Assist. Scrollen Sie, bis Sie Context Exclusion File (Datei zum Kontextausschluss) sehen.
Ändern Sie im Textfeld .aiexclude in den gewünschten Speicherort.
Die von Ihnen ausgewählte Datei wird jetzt als Datei mit Kontextausschlüssen festgelegt.
IntelliJ
Das Konfigurieren von Einstellungen für .aiexclude- und .gitignore-Dateien wird in JetBrains-IDEs nicht unterstützt.
Kontextausschluss für .gitignore ändern
Standardmäßig ist die Datei .gitignore für den Kontextausschluss aktiviert. Die Datei muss sich im Stammordner für Gemini Code Assist befinden. .gitignore-Dateien in Unterverzeichnissen werden nicht berücksichtigt oder zusammengeführt.
So deaktivieren Sie den Kontextausschluss für .gitignore-Dateien:
Klicken Sie in der Aktivitätsleiste auf die EinstellungenVerwalten > Einstellungen.
Klicken Sie im Fenster Einstellungen auf Erweiterungen > Gemini Code Assist. Scrollen Sie zu Context Exclusion Gitignore.
Entfernen Sie das Häkchen aus dem Kästchen.
.gitignore-Dateien sind jetzt deaktiviert, um anzugeben, welche Dateien von Gemini Code Assist ignoriert werden sollen.
.aiexclude-Datei schreiben
Eine .aiexclude-Datei hat die folgende Syntax:
Beispiele
Die folgenden Beispiele zeigen, wie Sie eine .aiexclude-Datei konfigurieren können:
Blockieren Sie alle Dateien mit dem Namen apikeys.txt im Verzeichnis, das die Datei .aiexclude enthält, oder in einem Unterverzeichnis:
apikeys.txt
Alle Dateien mit der Dateiendung .key im Verzeichnis, das die Datei .aiexclude enthält, oder in einem Unterverzeichnis dieses Verzeichnisses blockieren:
*.key
Blockieren Sie nur die Datei apikeys.txt im selben Verzeichnis wie die Datei .aiexclude, aber keine Unterverzeichnisse:
/apikeys.txt
Alle Dateien im Verzeichnis my/sensitive/dir und allen Unterverzeichnissen blockieren. Der Pfad sollte relativ zum Verzeichnis sein, das die Datei .aiexclude enthält.
my/sensitive/dir/
Blockiert alle Dateien im Verzeichnis foo und seinen Unterverzeichnissen mit Ausnahme der Datei mit dem Namen bar.txt im Verzeichnis „foo“.
foo/* !foo/bar.txt
Zugriff auf Index für die Codeanpassung steuern
Standardmäßig werden bei der Codeanpassung alle unterstützten Codedateien in den von Ihnen angegebenen Repositories indexiert.
Um zu verhindern, dass Code, der nicht im Kontext verwendet werden soll, offengelegt wird, können Sie mit Branch-Mustern den Zugriff auf Ihren Index steuern und einen stabilen Branch wie main verwenden.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-29 (UTC)."],[[["\u003cp\u003eGemini Code Assist indexes all supported code files in your repositories by default, but you can exclude specific files or subtrees using an \u003ccode\u003e.aiexclude\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eAn \u003ccode\u003e.aiexclude\u003c/code\u003e file uses a similar syntax to \u003ccode\u003e.gitignore\u003c/code\u003e, but an empty file blocks all files in its directory and subdirectories, and negation with an exclamation point is not supported.\u003c/p\u003e\n"],["\u003cp\u003eYou can block specific files, file types, or entire directories by listing their names, extensions, or relative paths in the \u003ccode\u003e.aiexclude\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eIf a file is added to \u003ccode\u003e.aiexclude\u003c/code\u003e after being indexed, it will be removed from the index within 24 hours.\u003c/p\u003e\n"]]],[],null,["\u003cbr /\u003e\n\n| **Preview**\n|\n| `.gitignore` support is in Preview. Products and features that are\n| in preview are available \"as is\".\n\nGemini Code Assist supports excluding files from your context for code\ngeneration, code completion, code transformation, and chat. For Enterprise\nusers, this also includes code customization.\n\nIn many scenarios, you'll have specific files or subtrees that you don't want\nto have included in your context.\n\nYou can exclude these files through the use of an `.aiexclude` or `.gitignore`\nfile.\n| **Note:** For [code customization](/gemini-code-assist/docs/code-customization-overview) only the `.aiexclude` file is used.\n\nConfigure context exclusion settings\n\nThis section shows you how to configure settings for `.aiexclude` and\n`.gitignore` files.\n\nChange .aiexclude file to your preferred file\n\nBy default, context exclusion is set to use `.aiexclude`. To change this setting\nin your IDE, follow these steps: \n\nVS Code\n\n1. In the activity bar, click\n settings **Manage** \\\u003e\n **Settings**.\n\n2. In the **Settings** window, navigate to **Extensions** \\\u003e\n **Gemini Code Assist** . Scroll until you find **Context Exclusion File**.\n\n3. In the text field, change `.aiexclude` to your preferred location.\n\nYour preferred file is now set as the context exclusion file.\n\nIntelliJ\n\nConfiguring settings for `.aiexclude` and `.gitignore` files isn't\nsupported in JetBrains IDEs.\n\nChange .gitignore context exclusion\n\nBy default, the `.gitignore` file is enabled for context exclusion. The file\nmust be located in the root working folder for\nGemini Code Assist. `.gitignore` files located in subdirectories\nwon't be considered or merged.\n\nTo disable `.gitignore` files from context exclusion, follow these steps:\n\n1. In the activity bar, click\n settings **Manage** \\\u003e\n **Settings**.\n\n2. In the **Settings** window, navigate to **Extensions** \\\u003e\n **Gemini Code Assist** . Scroll until you find **Context Exclusion Gitignore**.\n\n3. Unselect the checkbox.\n\n `.gitignore` files are now disabled for specifying file Gemini Code Assist to ignore.\n\nWrite an `.aiexclude` file **Note:** In the event that a conflict exists between `.aiexclude` and `.gitignore`, the `.aiexclude` directive preempts `.gitignore` directives.\n\nAn `.aiexclude` file follows the following syntax:\n\nExamples\n\nThe following examples demonstrate how you can configure an `.aiexclude` file:\n\n- Block all files named `apikeys.txt` at or below the directory that contains\n the `.aiexclude` file:\n\n apikeys.txt\n\n- Block all files with the `.key` file extension at or below the directory that\n contains the `.aiexclude` file:\n\n *.key\n\n- Block only the `apikeys.txt`file at the same directory as the `.aiexclude`\n file, but not any subdirectories:\n\n /apikeys.txt\n\n- Block all files in the directory `my/sensitive/dir` and all subdirectories.\n The path should be relative to the directory that contains the `.aiexclude`\n file.\n\n my/sensitive/dir/\n\n- Blocks all the files in directory `foo` and its subdirectories except file\n named `bar.txt` in the foo directory.\n\n foo/*\n !foo/bar.txt\n\nControl access to index for code customization\n\nBy default, code customization indexes all the\n\n[supported code files](/gemini-code-assist/docs/code-customization-overview#limitations)\nin your specified repositories.\n\nTo prevent exposure of code that you don't want to to be used in the context,\nyou can use branch patterns to\n\n[control access to your index](/gemini-code-assist/docs/code-customization#control_access_to_your_index_using_repository_groups)\nand use a stable branch, such as `main`.\n\nAlternatively, you can also exclude files from the context by\n[creating an `.aiexclude` file](#write_an_aiexclude_file)."]]