Skip to main content

Búsqueda de código público que coincida con sugerencias de GitHub Copilot

Si permites que GitHub Copilot haga sugerencias que coincidan con código disponible de forma pública, Copilot mostrará referencias al código coincidente que se encuentre.

This version of this article is for Copilot in JetBrains IDEs. For Copilot on other platforms, click the appropriate tab above.

Limitations

References to matching code are currently only available in JetBrains IDEs, Visual Studio Code, and on the GitHub website.

Prerequisites

References to matching code are only generated if Copilot is configured to allow suggestions that match publicly available code. This is configured in either your personal or organization settings. For more information, see Managing Copilot policies as an individual subscriber or Managing policies for Copilot in your organization.

About code referencing in GitHub Copilot

If you've allowed suggestions that match public code, GitHub Copilot can provide you with details of the code that a suggestion matches. This happens:

  • When you accept a code completion suggestion in the editor.
  • When a response in Copilot Chat includes matching code.

This feature is called code referencing.

Code referencing for Copilot code completion

When you accept a code completion suggestion that matches code in a public GitHub repository, an entry is added to the JetBrains log. The log entry includes the URLs of files containing matching code, and the name of the license that applies to that code, if any was found. This allows you to review these references and decide how to proceed. For example, you can decide what attribution to use, or whether you want to remove this code from your project.

Note

  • Code referencing for code completion only occurs for matches of accepted Copilot suggestions. Code you have written, and Copilot suggestions you have altered, are not checked for matches to public code.
  • Typically, matches to public code occur in less than one percent of Copilot suggestions, so you should not expect to see code references for many suggestions.

Code referencing for Copilot Chat

When Copilot Chat provides a response that includes code that matches code in a public GitHub repository, this is indicated at the end of the response with a link to display details of the matched code in the editor.

How code referencing finds matching code

Copilot code referencing searches for matches by taking the code suggestion, plus some of the code that will surround the suggestion if it is accepted, and comparing it against an index of all public repositories on GitHub.com. Code in private GitHub repositories, or code outside of GitHub, is not included in the search process. The search index is refreshed every few months. As a result, newly committed code, and code from public repositories deleted before the index was created, may not be included in the search. For the same reason, the search may return matches to code that has been deleted or moved since the index was created.

View code references for code completion

You can view code references in the log file for your JetBrains IDE.

  1. In your JetBrains IDE, select Help > Show Log in Finder/Explorer.

    The log file is displayed in your file manager. For example, for IntelliJ IDEA the log file is called idea.log.

  2. Open the log file in your JetBrains IDE.

  3. Search for "[Public Code References]."

Example log entry

2025-02-26 09:22:12,045 [5581906] INFO - #copilot - [Public Code References] Text found matching public code in file:///Users/mona-lisa/git-repos/test-repo/fizzbuzz.js [Ln 1, Col 10] near fizzBuzz() ...:
  1) [NOASSERTION] https://github.com/nixsticks/todos/blob/ae427a721c7784da64a619ba17f60637fe1cc819/Loops/fizzbuzz/fizzbuzz.js
  2) [GPL-3.0] https://github.com/voloslg/algocasts/blob/34b423517486f908ca167b390d3b8bd05653829f/exercises/fizzbuzz/index.js

The log entry includes the following details:

  • The date and time you accepted the suggestion.
  • A "Public Code References" message telling you that matching code was found.
  • The path to the file in which the suggestion was added.
  • The line and column number where the suggestion was added.
  • A list of matches, including:
    • The license type for the matching code—or NOASSERTION if no license was found.
    • The URL of the file on GitHub.com where the matching code was found.

Verifying the code referencing functionality

You can verify that code referencing is working by prompting Copilot to add some commonly used code and checking the output in the log file for your IDE.

  1. Display the log file for your JetBrains IDE, as described in the previous section.

  2. Create a file called fizz-buzz.js and open it in the JetBrains editor.

  3. In the editor, type:

    function fizzBuzz()
    

    With a space after the closing parenthesis.

    GitHub Copilot should suggest code to complete the function. Typically the suggestion will be a common implementation of the fizz buzz algorithm that will match publicly available code on the GitHub website.

  4. Accept the suggestion by pressing Tab.

  5. Check whether a "[Public Code References]" entry has been added to the log file.

View code references for Copilot Chat

If a response in Copilot Chat includes matching code, this is indicated at the end of the response by the following text:

Similar code found with n license types - View matches

  1. Click View matches to display details of the matched code in a new editor tab.

    For each example of matching code, the editor displays:

    • The license type for the matching code, if known.
    • The URL of the file on GitHub.com where the matching code was found.
    • A code snippet showing the matching code.
  2. In the editor, Ctrl+click (Windows/Linux) or Command+click (Mac) a URL to view the full file on GitHub.com.