Skip to main content

GitHub Copilot からのコンテンツの除外

Copilot が特定のコンテンツにアクセスできないようにすることができます。

この機能を使用できるユーザーについて

リポジトリ管理者と組織の所有者は、コンテンツの除外設定を管理できます。

リポジトリの "保持" ロールを持つユーザーは、そのリポジトリのコンテンツ除外設定を表示できますが、編集することはできません。

GitHub Copilot Business または GitHub Copilot Enterprise にサブスクリプションしている組織

Copilot のコンテンツ除外について

Note

GitHub Command Palette からのコンテンツの除外は現在パブリック ベータ版であり、変更される可能性があります。

内容の除外を使用すると、特定のファイルを無視するように Copilot を構成できます。 Copilot からコンテンツを除外する場合:

  • コード完成は、影響を受けるファイルでは使用できません。
  • 影響を受けるファイル内のコンテンツは、その他のファイルのコード完成候補を通知しません。
  • 影響を受けるファイル内のコンテンツは、GitHub Copilot Chat の応答を通知しません。

内容の除外設定は、GitHub Copilot Business または GitHub Copilot Enterprise サブスクリプションの一部としてシートが付与されており、内容の除外が構成されている組織のメンバーにのみ適用されます。

指定したファイルにアクセスできる他のユーザーには、指定されたファイルを参照するコード補完候補と GitHub Copilot Chat 応答が表示されます。

コンテンツ除外の可用性

ツールコード完成のサポートCopilot Chat のサポート
Visual Studio
Visual Studio Code
JetBrains IDE
Vim/Neovim適用なし
Azure Data Studio適用なし
GitHub.com適用なし

コンテンツ除外の制限

  • Visual Studio Code の Copilot Chat では、質問の @github チャット参加者を使用する場合、コンテンツの除外は適用されません。
  • 除外されていないファイルで IDE から情報が提供されている場合、Copilot が除外されたファイルのセマンティック情報を使用する可能性があります。 このようなコンテンツの例としては、コードで使用されるシンボルの型情報やカーソル定義などがあります。

GitHub に送信されたデータ

コンテンツ除外を構成すると、クライアント (例: VS Code の Copilot 拡張子) は、現在のリポジトリ URL を GitHub サーバーに送信し、サーバーが正しいポリシーをクライアントに返すようにします。 これらの URL はいずれにあるログにも記録されません。

リポジトリのコンテンツ除外の構成

リポジトリ設定を使用して、GitHub Copilot で無視するようにするリポジトリ内のコンテンツを指定できます。

  1. GitHub で、リポジトリのメイン ページに移動します。

  2. リポジトリ名の下にある [設定] をクリックします。 [設定] タブが表示されない場合は、 [] ドロップダウン メニューを選び、 [設定] をクリックします。

    タブを示すリポジトリ ヘッダーのスクリーンショット。 [設定] タブが濃いオレンジ色の枠線で強調表示されています。

  3. サイドバーの [コードと自動化] セクションで、[ Copilot] をクリックします。

    リポジトリがその親組織から除外を継承している場合、これらの除外の詳細を含むページの上部に 1 つのグレー ボックスが表示されます。 これらの設定は編集できません。

  4. [このリポジトリで除外するパス] のボックスに、Copilot を除外するファイルへのパスを入力します。

    各パスを別々の行にして、形式 - "/PATH/TO/DIRECTORY/OR/FILE" を使用します。 行頭を # にすることで、コメントを追加できます。

    Tip

    fnmatch パターン マッチング表記を使用して、ファイル パスを指定できます。 パターンでは大文字と小文字が区別されません。 ruby-doc.org ドキュメントの「File」(ファイル) を参照してください。

リポジトリ設定で指定されたパスの例

YAML
- "/src/some-dir/kernel.rs"

Ignore the /src/some-dir/kernel.rs file in this repository.

- "secrets.json"

Ignore files called secrets.json anywhere in this repository.

- "secret*"

Ignore all files whose names begin with secret anywhere in this repository.

- "*.cfg"

Ignore files whose names end with .cfg anywhere in this repository.

- "/scripts/**"

Ignore all files in or below the /scripts directory of this repository.

# Ignore the `/src/some-dir/kernel.rs` file in this repository.
- "/src/some-dir/kernel.rs"

# Ignore files called `secrets.json` anywhere in this repository.
- "secrets.json"

# Ignore all files whose names begin with `secret` anywhere in this repository.
- "secret*"

# Ignore files whose names end with `.cfg` anywhere in this repository.
- "*.cfg"

# Ignore all files in or below the `/scripts` directory of this repository.
- "/scripts/**"

組織のコンテンツ除外の構成

組織設定を使用して、GitHub Copilot を無視するようにするファイルを指定できます。 ファイルは、Git リポジトリ内、または Git の管理下にないファイル システム上の任意の場所に配置できます。

  1. GitHub の右上隅で、プロフィール写真を選択し、 あなたの組織をクリックします。

  2. 組織の隣の [設定] をクリックします。

  3. 左側のサイドバーで、[ Copilot] をクリックし、[コンテンツの除外] をクリックします。

  4. [除外するリポジトリとパス] のボックスに、Copilot を除外するファイルの詳細を入力します。

    任意の場所 (Git リポジトリ内または他の場所) にあるファイルを除外するには、 "*": を入力し、その後に除外するファイル (複数可) へのパスを入力します。 複数のファイル パス パターンを指定する場合は、各パターンを個別の行に一覧表示します。

    Git リポジトリのファイルを Copilot から除外するには、リポジトリへの参照を 1 行に入力し、その後にリポジトリ内の場所へのパスを各パスが別々の行になるように入力します。 次の形式を使用して、REPOSITORY-REFERENCE を、除外するファイルを含むリポジトリへの参照に置き換えます。

    REPOSITORY-REFERENCE:
      - "/PATH/TO/DIRECTORY/OR/FILE"
      - "/PATH/TO/DIRECTORY/OR/FILE"
      - ...
    

    リポジトリは、さまざまなプロトコルを使用して参照できます。 REPOSITORY-REFERENCE には、次のいずれかの構文を使用できます。また、リポジトリのローカルでの複製方法に関係なく、Copilot はこれらの構文と一致します。

    http[s]://host.xz[:port]/path/to/repo.git/
    
    git://host.xz[:port]/path/to/repo.git/
    
    [user@]host.xz:path/to/repo.git/
    
    ssh://[user@]host.xz[:port]/path/to/repo.git/
    

    リポジトリに対して無視するパスの計算では、REPOSITORY-REFERENCEuser@ 部分と :port 部分は無視されます。

    Azure DevOps では、REPOSITORY-REFERENCE を指定するときに新しい (dev.azure.com) または古い (visualstudio.com) ホスト形式を使用でき、どのホストを使用してリポジトリをローカルにクローンしたかに関係なく、Copilot はそれらに一致します。

    Tip

    fnmatch パターン マッチング表記を使用して、ファイル パスを指定できます。 パターンでは大文字と小文字が区別されません。 ruby-doc.org ドキュメントの「File」(ファイル) を参照してください。

組織設定のリポジトリとパスの例

YAML
"*":
  - "**/.env"

Ignore all .env files from all file system roots (Git and non-Git). For example, this excludes REPOSITORY-PATH/.env and also /.env. This could also have been written on a single line as:

"*": ["**/.env"]

octo-repo:

In the octo-repo repository in this organization:

  - "/src/some-dir/kernel.rs"

Ignore the /src/some-dir/kernel.rs file.

https://github.com/primer/react.git:

In the primer/react repository on GitHub:

  - "secrets.json"

Ignore files called secrets.json anywhere in this repository.

  - "/src/**/temp.rb"

Ignore files called temp.rb in or below the /src directory.

git@github.com:*/copilot:

In the copilot repository of any GitHub organization:

  - "/__tests__/**"

Ignore any files in or below the /__tests__ directory.

  - "/scripts/*"

Ignore any files in the /scripts directory.

git@gitlab.com:gitlab-org/gitlab-runner.git:

In the gitlab-org/gitlab-runner repository on GitLab:

  - "/main_test.go"

Ignore the /main_test.go file.

  - "{server,session}*"

Ignore any files with names beginning with server or session anywhere in this repository.

  - "*.m[dk]"

Ignore any files with names ending with .md or .mk anywhere in this repository.

  - "**/package?/*"

Ignore files directly within directories such as packages or packaged anywhere in this repository.

  - "**/security/**"

Ignore files in or below any security directories, anywhere in this repository.

# Ignore all `.env` files from all file system roots (Git and non-Git).
# For example, this excludes `REPOSITORY-PATH/.env` and also `/.env`.
# This could also have been written on a single line as:
#
# "*": ["**/.env"]
"*":
  - "**/.env"

# In the `octo-repo` repository in this organization:
octo-repo:
  # Ignore the `/src/some-dir/kernel.rs` file.
  - "/src/some-dir/kernel.rs"

# In the `primer/react` repository on GitHub:
https://github.com/primer/react.git:
  # Ignore files called `secrets.json` anywhere in this repository.
  - "secrets.json"
  # Ignore files called `temp.rb` in or below the `/src` directory.
  - "/src/**/temp.rb"

# In the `copilot` repository of any GitHub organization:
git@github.com:*/copilot:
  # Ignore any files in or below the `/__tests__` directory.
  - "/__tests__/**"
  # Ignore any files in the `/scripts` directory.
  - "/scripts/*"

# In the `gitlab-org/gitlab-runner` repository on GitLab:
git@gitlab.com:gitlab-org/gitlab-runner.git:
  # Ignore the `/main_test.go` file.
  - "/main_test.go"
  # Ignore any files with names beginning with `server` or `session` anywhere in this repository.
  - "{server,session}*"
  # Ignore any files with names ending with `.md` or `.mk` anywhere in this repository.
  - "*.m[dk]"
  # Ignore files directly within directories such as `packages` or `packaged` anywhere in this repository.
  - "**/package?/*"
  # Ignore files in or below any `security` directories, anywhere in this repository.
  - "**/security/**"

コンテンツ除外の変更をテストする

IDE を使用して、コンテンツ除外の変更が想定どおりに動作していることを確認できます。

IDE にコンテンツ除外の変更を伝達する

コンテンツの除外を追加または変更し、設定が既に読み込まれている IDE で有効になるまでに最大で 30 分かかることがあります。 待機しない場合は、次の手順を使用して、コンテンツの除外設定を手動で再読み込みできます。

  • JetBrains IDE と Visual Studio の場合は、アプリケーションを閉じて再度開くことで、コンテンツの除外設定を再読み込みします。
  • Visual Studio Code の場合は、次の手順に従ってコンテンツの除外設定を再読み込みします。
    1. コマンド パレットにアクセスします。 たとえば、Shift + Command + P (Mac) / Ctrl + Shift + P (Windows/Linux) を押します。
    2. 次のコマンドを入力します: reload
    3. [開発者: ウィンドウをリロードする] を選択します。
  • Vim/Neovim については、ファイルを開くたびに GitHub からコンテンツ除外が自動的にフェッチされます。

コンテンツの除外をテストする

使用している IDE に応じて、コンテンツの除外をテストする方法はいくつかあります。

  1. コンテンツ除外の影響を受けると予想されるファイルを開きます。
  2. コンテンツが除外されているかどうかをテストするには、次の 1 つ以上の手法を使用します。
    • JetBrains IDEs、Visual Studio、および Visual Studio Code においては、ステータスバーの Copilot を確認してください。 Copilot コンテンツ除外がこのファイルに適用される場合、Copilot アイコンには斜線が表示されます。 アイコンをホバーすると、組織または親リポジトリがこのファイルに対して Copilot を無効にしたかどうかを表示します。
    • JetBrains IDE、Visual Studio、および Visual Studio Code では、Copilot Chat でコンテンツの除外をテストすることもできます。 Copilot Chat ウィンドウを開き、除外されたファイルについて Copilot Chat に質問します。 コンテンツが正常に除外された場合、Copilot は質問に答えることができません。また、コンテンツの除外ルールにより、一部のファイルが会話から除外されたことを説明します。
    • Vim/Neovim でファイルの入力を開始します。 入力時に GitHub Copilot がインライン検索候補を提供しなくなった場合、ファイルは除外されています。

参考資料