Skip to main content

GitHub Copilot のコンテンツ除外の構成

GitHub Copilot によるコード補完候補への情報として、指定したファイルが使用されないようにできます。 GitHub Copilot は、除外されたファイルでは使用できません。

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

Repository administrators and organization owners can manage the content exclusion settings for GitHub Copilot.

People with the "Maintain" role for a repository can view the content exclusion settings for that repository, but can't change these settings. For more information, see "Organizationのリポジトリロール."

This feature is available for organization and enterprise accounts with a Copilot Business subscription, and for enterprise accounts with a Copilot Enterprise subscription.

注:

  • GitHub Command Palette からのコンテンツの除外は現在パブリック ベータ版であり、変更される可能性があります。
  • この機能は、Visual Studio、Visual Studio Code、JetBrains IDE、および neovim 内でサポートされています。 サポートされている JetBrains IDE の詳細については、「GitHub Copilot の概要」を参照してください。

コンテンツの除外の構成について

特定のファイルを GitHub Copilot で使用できないようにしたい場合があります。 これらのファイルを無視するように GitHub Copilot を構成できます。 これを行うには、リポジトリまたは組織の設定で除外されたコンテンツへのパスを指定します。

コンテンツの除外を指定すると、次の 2 つの影響があります。

  • 影響を受けるファイルのコンテンツは、GitHub Copilot が他のファイルで行うコード補完候補への情報として使用されません。
  • GitHub Copilot コード補完は、影響を受けるファイルでは使用できません。

コンテンツの除外を追加または変更し、設定が既に読み込まれている IDE でこれが有効になるまでに最大で 30 分かかることがあります。 独自の IDE に変更を適用して、コンテンツの除外設定を強制的に再読み込みすることができます。 詳細については、「コンテンツ除外の変更を IDE に反映する」を参照してください。

制限事項

  • 現在、GitHub Copilot からコンテンツを除外すると、コードの完了にのみ影響します。 GitHub Copilot Chat は、これらの設定を使用しても影響しません。
  • コンテンツ除外を使用すると、Copilot が除外されたファイルのコンテンツに直接アクセスできなくなります。 Copilot は、IDE によって提供されるセマンティック情報 (TYPE 情報や、コードで使用されるシンボルのホバー定義など) から、除外されていないファイルに関する情報を引き出すことができます。 IDE は、除外されたファイルからこの情報を取得する可能性があります。

何を除外することができますか?

リポジトリの設定でコンテンツの除外を指定するには、そのリポジトリ内のファイルのみを除外できます。

Organization の設定でコンテンツの除外を指定する場合は、GitHub.com でホストされている Git ベースのリポジトリ、または次の構文のいずれかを使用して、アクセス可能な任意の場所にあるファイルを除外することができます。

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/

注: Copilot Business または Copilot Enterprise サブスクリプションを持つ GitHub Organization の設定によって内容が除外される可能性があることに注意してください。 除外されたファイルは、除外が定義された organization が所有していないリポジトリ内にある可能性があります。 除外されたファイルは、GitHub でホストされていない Git ベースのリポジトリ内に配置されている場合もあります。

コンテンツの除外設定の影響を受ける対象者

GitHub Copilot コンテンツの除外設定は、Copilot を使用するすべてのユーザーに適用されるわけではありません。

内容の除外設定は、GitHub Copilot Business または GitHub Copilot Enterprise サブスクリプションの一部としてシートが付与されており、内容の除外が構成されているのと同じ Enterprise のメンバーであるユーザーにのみ適用されます。 指定したファイルにアクセスできるその他のユーザーには、コンテンツの除外設定による影響はなく、コード補完候補が表示されます。

Enterprise の設定でコンテンツの除外を指定することはできません。 ただし、Organization またはリポジトリ設定で定義されたコンテンツ除外はすべて、Copilot Business または Copilot Enterprise サブスクリプションの一部として Copilot シートを付与された Enterprise のすべてのメンバーに適用されます。

つまり、たとえば、Enterprise X に属する Organization の管理者の場合、GitHub または他の場所でホストされている Git ベースのリポジトリ内のファイルの除外を設定でき、その除外は Enterprise X の任意の Organization から Copilot Business または Copilot Enterprise ライセンスを取得したすべてのユーザーに適用されます。

ただし、GitHub リポジトリでの除外が定義されている場合は、そのリポジトリの設定、またはリポジトリを所有する組織の設定内で定義することをお勧めします。 これにより、企業内の別の組織の設定で除外を定義する場合よりも簡単に、リポジトリに適用されている除外を特定できます。

GitHub に送信されたデータ

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

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

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

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

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

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

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

    リポジトリが同じエンタープライズ内の組織から除外を継承している場合、これらの除外の詳細を含むページの上部に 1 つまたは複数のグレー ボックスが表示されます。 これらの設定は編集できません。

    : リポジトリに影響を与える除外は、リポジトリ設定で定義されているものに加えて、GitHub エンタープライズ内の任意の組織の設定で定義できます。

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

    Copilot のリポジトリ設定の [除外するパス] テキスト ボックスのスクリーンショット。

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

    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 secret anywhere in this repository.

- "*.cfg"

Ignore files whose names end .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 `secret` anywhere in this repository.
- "secret*"

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

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

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

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

  1. GitHub.com の右上隅にあるプロファイル写真を選択し、次に自分の組織をクリックします。

    @octocat のプロファイル写真の下にあるドロップダウン メニューのスクリーンショット。 [Your organizations] (自分の組織) が濃いオレンジ色の枠線で囲まれています。

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

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

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

    ファイルを Copilot から除外するリポジトリごとに、リポジトリへの参照を 1 行に入力し、その後にリポジトリ内の場所へのパスを各パスが別々の行になるように入力します。 次の形式を使用します。

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

    REPOSITORY-REFERENCE では、次の構文がサポートされています。

    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 部分は無視されます。
    • 各リポジトリ参照には、単一の * ワイルドカードを含めることができます。 たとえば、https://github.com/octo-org/*octo-org 組織内のすべてのリポジトリと一致します。

    fnmatch パターン マッチング表記を使用して、ファイル パスを指定できます。 詳細については、ruby-doc.org ドキュメントの「File」(ファイル) を参照してください。

    : パターンでは大文字と小文字が区別されません。

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

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

Ignore all .env files at any path, in any repository. This setting applies to all repositories, not just to those on GitHub.com. 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 server or session, anywhere in this repository.

  - "*.m[dk]"

Ignore any files with names ending .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 at any path, in any repository.
# This setting applies to all repositories, not just to those on GitHub.com.
# 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 `server` or `session`, anywhere in this repository.
  - "{server,session}*"
  # Ignore any files with names ending `.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/**"

コンテンツの除外設定に対する変更のレビュー

組織の所有者は、コンテンツの除外に加えられた変更を確認できます。

  1. 組織の設定 (説明はこちら) またはリポジトリの設定 (説明はこちら) の [コンテンツの除外] ページを開きます。

  2. ページの一番下までスクロールします。

    設定を最後に変更したユーザーの名前と、この変更を行った日時に関する情報が表示されます。

  3. 最後の変更の時刻をクリックします。

    最後の編集に関する情報のスクリーンショット。 変更時刻のリンクが濃いオレンジの枠線でハイライトされています。

    : 組織の所有者の場合、最終変更時刻はリンクのみです。

    組織の [監査ログ] ページが表示され、最後にログに記録された copilot.content_exclusion_changed アクションの発生が表示されます。

    リポジトリ設定ページからクリックした場合、監査ログがフィルター処理され、そのリポジトリのコンテンツ除外に対する変更のみが表示されます。

  4. 各エントリの末尾にある省略記号 (...) をクリックすると、詳細が表示されます。

    "excluded_paths" エントリが切り捨てられている場合は、切り捨てられた値にカーソルを合わせると、完全なエントリが表示されます。 これにより、変更が保存された後の除外設定のコンテンツが表示されます。

    "copilot.content_exclusion_changed" アクションの監査ログの詳細のスクリーンショット。 省略記号ボタンがハイライトされています。

設定変更の影響を確認する

Copilot のコンテンツ除外を変更したときに、設定によって指定されたファイル内のコードの提案から Copilot がブロックされることをチェックできます。

ファイルに対して Copilot が無効になっていることを確認するには、エディタでファイルを開き、コメントなどのコード行の入力を開始します。 通常、入力時に Copilot からコード補完候補が表示されます。 コンテンツの除外によって Copilot が無効になっている場合、コード補完候補は提供されず、ファイルの内容は他のファイルで候補を生成するためには使用されません。

IDE での設定変更の確認

Visual Studio、VS Code、またはサポートされている JetBrains IDE で作業している場合、Copilot アイコンは、Copilot がコンテンツ除外によって無効になったことを示します。

  1. コンテンツ除外の影響を受けると予想されるファイルを開きます。

    Copilot コンテンツ除外がこのファイルに適用される場合、ステータス バーの Copilot アイコンには斜線が表示されます。

  2. このアイコンをホバーします。 Organization または親リポジトリがこのファイルに対して Copilot を無効にしたかどうかを示すポップアップ メッセージが表示されます。

    VS Code ツール バーの Copilot 無効ポップアップのスクリーンショット。

ノート/メモ: Visual Studio と VS Code では、Copilot 拡張機能のログを表示して、Copilot アイコンをホバーしなくても、コンテンツ除外の詳細を確認できます。 詳しくは、「環境での GitHub Copilot のログの表示」を参照してください。

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

Neovim で作業している場合、ファイルを開くたびに GitHub からコンテンツの除外が取得されます。 ただし、Visual Studio、VS Code、またはサポートされている JetBrains IDE で作業している場合は、設定変更の影響を確認するために最大で 30 分待つ必要がある場合があります。 または、手動で IDE にコンテンツ除外設定を再読み込みすることもできます。

コンテンツの除外を Visual Studio に再読み込みするには、アプリケーションを閉じてから再度開きます。

コンテンツの除外を VS Code にリロードする方法:

  1. コマンド パレットにアクセスします。 たとえば、Shift + Command + P (Mac) / Ctrl + Shift + P (Windows/Linux) を押します。
  2. 次のコマンドを入力します: reload
  3. [開発者: ウィンドウをリロードする] を選択します。

コンテンツ除外を JetBrains IDE にリロードするには、アプリケーションを閉じてから再度開くか、GitHub からログアウトしてから再度ログインします。

  1. ステータス バーの Copilot アイコンをクリックし、[GitHub からログアウト] を選択します。
  2. ステータス バーの Copilot アイコンに斜線が表示されるようになりました。 それをクリックして、[GitHub にログイン] を選択 します。
  3. 「GitHub にサインインしてください」というメッセージとデバイス コードが表示されます。 [コピーして開く] をクリックします。
  4. [デバイスのアクティベーション] ページで、デバイスコードを貼り付けて [続行] をクリックします。
  5. 次のページで、[Authorize GitHub Copilot プラグイン] をクリックします。

参考資料