Mengecualikan file dari penggunaan Gemini Code Assist
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Gemini Code Assist mendukung pengecualian file dari konteks Anda untuk pembuatan kode, penyelesaian kode, transformasi kode, dan chat. Untuk pengguna Enterprise, hal ini juga mencakup penyesuaian kode.
Dalam banyak skenario, Anda akan memiliki file atau subpohon tertentu yang tidak ingin disertakan dalam konteks Anda.
Anda dapat mengecualikan file ini melalui penggunaan file .aiexclude atau .gitignore.
Mengonfigurasi setelan pengecualian konteks
Bagian ini menunjukkan cara mengonfigurasi setelan untuk file .aiexclude dan .gitignore.
Mengubah file .aiexclude ke file pilihan Anda
Secara default, pengecualian konteks disetel untuk menggunakan .aiexclude. Untuk mengubah setelan ini
di IDE Anda, ikuti langkah-langkah berikut:
VS Code
Di panel aktivitas, klik
setelanKelola >
Setelan.
Di jendela Settings, buka Extensions >
Gemini Code Assist. Scroll hingga Anda menemukan File Pengecualian Konteks.
Di kolom teks, ubah .aiexclude ke lokasi pilihan Anda.
File pilihan Anda kini ditetapkan sebagai file pengecualian konteks.
IntelliJ
Mengonfigurasi setelan untuk file .aiexclude dan .gitignore tidak
didukung di IDE JetBrains.
Mengubah pengecualian konteks .gitignore
Secara default, file .gitignore diaktifkan untuk pengecualian konteks. File
harus berada di folder kerja root untuk
Gemini Code Assist. File .gitignore yang berada di subdirektori tidak akan dipertimbangkan atau digabungkan.
Untuk menonaktifkan file .gitignore dari pengecualian konteks, ikuti langkah-langkah berikut:
Di panel aktivitas, klik
setelanKelola >
Setelan.
Di jendela Settings, buka Extensions >
Gemini Code Assist. Scroll hingga Anda menemukan Context Exclusion Gitignore.
Hapus centang pada kotak.
File .gitignore kini dinonaktifkan untuk menentukan file yang akan diabaikan oleh Gemini Code Assist.
Menulis file .aiexclude
File .aiexclude mengikuti sintaksis yang sama dengan file .gitignore.
Contoh
Contoh berikut menunjukkan cara mengonfigurasi file .aiexclude:
Blokir semua file bernama apikeys.txt di atau di bawah direktori yang berisi file .aiexclude:
apikeys.txt
Blokir semua file dengan ekstensi file .key di atau di bawah direktori yang berisi file .aiexclude:
*.key
Hanya blokir file apikeys.txt di direktori yang sama dengan file .aiexclude, tetapi tidak di subdirektori mana pun:
/apikeys.txt
Blokir semua file di direktori my/sensitive/dir dan semua subdirektorinya.
Jalur harus bersifat relatif terhadap direktori yang berisi file
.aiexclude.
my/sensitive/dir/
Memblokir semua file di direktori foo dan subdirektorinya, kecuali file
bernama bar.txt di direktori foo.
foo/*
!foo/bar.txt
Mengontrol akses ke indeks untuk penyesuaian kode
Secara default, penyesuaian kode mengindeks semua
file kode yang didukung
di repositori yang Anda tentukan.
Untuk mencegah tereksposnya kode yang tidak ingin Anda gunakan dalam konteks, Anda
dapat menggunakan pola cabang untuk
mengontrol akses ke indeks Anda
dan menggunakan cabang yang stabil, seperti main.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-10 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\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 same syntax as a `.gitignore` file.\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 be used in the context, you\ncan 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)."]]