Loại trừ các tệp khỏi việc sử dụng tính năng Gemini Code Assist
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Gemini Code Assist hỗ trợ loại trừ các tệp khỏi ngữ cảnh của bạn để tạo mã, hoàn thành mã, chuyển đổi mã và trò chuyện. Đối với người dùng Enterprise, điều này cũng bao gồm việc tuỳ chỉnh mã.
Trong nhiều trường hợp, bạn sẽ có các tệp hoặc cây con cụ thể mà bạn không muốn đưa vào ngữ cảnh của mình.
Bạn có thể loại trừ các tệp này bằng cách sử dụng tệp .aiexclude hoặc .gitignore.
Định cấu hình chế độ cài đặt loại trừ theo bối cảnh
Phần này hướng dẫn bạn cách định cấu hình chế độ cài đặt cho các tệp .aiexclude và .gitignore.
Thay đổi tệp .aiexclude thành tệp mà bạn muốn
Theo mặc định, chế độ loại trừ theo bối cảnh được đặt để sử dụng .aiexclude. Để thay đổi chế độ cài đặt này trong IDE, hãy làm theo các bước sau:
VS Code
Trong thanh hoạt động, hãy nhấp vào settingsManage (Quản lý) > Settings (Cài đặt).
Trong cửa sổ Settings (Cài đặt), hãy chuyển đến Extensions (Tiện ích) > Gemini Code Assist. Di chuyển cho đến khi bạn thấy Tệp loại trừ theo bối cảnh.
Trong trường văn bản, hãy thay đổi .aiexclude thành vị trí bạn muốn.
Tệp bạn muốn hiện được đặt làm tệp loại trừ theo bối cảnh.
IntelliJ
Các IDE JetBrains không hỗ trợ việc định cấu hình chế độ cài đặt cho tệp .aiexclude và .gitignore.
Thay đổi tiêu chí loại trừ nội dung .gitignore
Theo mặc định, tệp .gitignore được bật để loại trừ theo bối cảnh. Tệp này phải nằm trong thư mục gốc đang hoạt động của Gemini Code Assist. Các tệp .gitignore nằm trong thư mục con sẽ không được xem xét hoặc hợp nhất.
Để tắt tính năng loại trừ theo bối cảnh đối với tệp .gitignore, hãy làm theo các bước sau:
Trong thanh hoạt động, hãy nhấp vào settingsManage (Quản lý) > Settings (Cài đặt).
Trong cửa sổ Settings (Cài đặt), hãy chuyển đến Extensions (Tiện ích) > Gemini Code Assist. Di chuyển cho đến khi bạn thấy Context Exclusion Gitignore.
Bỏ chọn hộp đánh dấu.
Các tệp .gitignore hiện đã bị vô hiệu hoá để chỉ định tệp mà Gemini Code Assist sẽ bỏ qua.
Viết một tệp .aiexclude
Tệp .aiexclude tuân theo cú pháp sau:
Ví dụ
Các ví dụ sau đây minh hoạ cách bạn có thể định cấu hình tệp .aiexclude:
Chặn tất cả các tệp có tên apikeys.txt tại hoặc bên dưới thư mục chứa tệp .aiexclude:
apikeys.txt
Chặn tất cả các tệp có đuôi .key tại hoặc bên dưới thư mục chứa tệp .aiexclude:
*.key
Chỉ chặn tệp apikeys.txt trong cùng thư mục với tệp .aiexclude, nhưng không chặn bất kỳ thư mục con nào:
/apikeys.txt
Chặn tất cả các tệp trong thư mục my/sensitive/dir và tất cả các thư mục con.
Đường dẫn phải tương ứng với thư mục chứa tệp .aiexclude.
my/sensitive/dir/
Chặn tất cả các tệp trong thư mục foo và các thư mục con của thư mục này, ngoại trừ tệp có tên bar.txt trong thư mục foo.
foo/*
!foo/bar.txt
Kiểm soát quyền truy cập vào chỉ mục để tuỳ chỉnh mã
Theo mặc định, tính năng tuỳ chỉnh mã sẽ lập chỉ mục tất cả các tệp mã được hỗ trợ trong các kho lưu trữ mà bạn chỉ định.
Để ngăn việc lộ mã mà bạn không muốn sử dụng trong ngữ cảnh, bạn có thể sử dụng các mẫu nhánh để kiểm soát quyền truy cập vào chỉ mục và sử dụng một nhánh ổn định, chẳng hạn như main.
Ngoài ra, bạn cũng có thể loại trừ các tệp khỏi ngữ cảnh bằng cách tạo tệp .aiexclude.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-31 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)."]]