You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Finding public code that matches GitHub Copilot suggestions
3
3
shortTitle: Find matching code
4
-
intro: 'If you allow {% data variables.product.prodname_copilot %} to make suggestions that match publicly available code, {% data variables.product.prodname_copilot_short %} will display references to any matching code that is found.'
4
+
intro: 'If you allow {% data variables.product.prodname_copilot %} to make suggestions that match publicly available code, {% data variables.product.prodname_copilot_short %} will display references to any similar code that is found.'
@@ -30,9 +30,15 @@ This version of this article is for {% data variables.product.prodname_copilot_s
30
30
31
31
{% endwebui %}
32
32
33
+
{% visualstudio %}
34
+
35
+
This version of this article is for {% data variables.product.prodname_copilot_short %} in {% data variables.product.prodname_vs %}. For {% data variables.product.prodname_copilot_short %} on other platforms, click the appropriate tab above.
36
+
37
+
{% endvisualstudio %}
38
+
33
39
## Limitations
34
40
35
-
References to matching code are currently only available in JetBrains IDEs, {% data variables.product.prodname_vscode %}, and on the {% data variables.product.github %} website.
41
+
References to matching code are currently available in JetBrains IDEs, {% data variables.product.prodname_vs %}, {% data variables.product.prodname_vscode %}, and on the {% data variables.product.github %} website.
36
42
37
43
## Prerequisites
38
44
@@ -58,14 +64,18 @@ If you've allowed suggestions that match public code, then whenever a response f
58
64
59
65
{% endwebui %}
60
66
67
+
{% visualstudio %}
68
+
69
+
{% data reusables.copilot.about-code-referencing %}
70
+
71
+
{% endvisualstudio %}
72
+
61
73
This feature is called code referencing.
62
74
63
75
{% jetbrains %}
64
76
65
77
### Code referencing for {% data variables.product.prodname_copilot_short %} code completion
66
78
67
-
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} 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.
68
-
69
79
{% data reusables.copilot.code-referencing-note %}
70
80
71
81
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}
@@ -85,10 +95,6 @@ When you accept a code completion suggestion that matches code in a public {% da
85
95
86
96
### Code referencing for {% data variables.product.prodname_copilot_short %} code completion
87
97
88
-
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to a {% data variables.product.prodname_copilot %} log. The log entry includes a link to a page on {% data variables.product.prodname_dotcom_the_website %} where you can view references to similar code in public {% data variables.product.prodname_dotcom %} repositories.
89
-
90
-
The linked web page includes details of any license identified for the repository where the matching code was found. Having reviewed the references, you can decide how to proceed. For example, you can decide what attribution to use, or whether you want to remove this code from your project.
91
-
92
98
{% data reusables.copilot.code-referencing-note %}
93
99
94
100
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}
@@ -97,6 +103,18 @@ The linked web page includes details of any license identified for the repositor
97
103
98
104
{% endvscode %}
99
105
106
+
{% visualstudio %}
107
+
108
+
### Code referencing for {% data variables.product.prodname_copilot_short %} code completion
109
+
110
+
{% data reusables.copilot.code-referencing-note %}
111
+
112
+
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}
113
+
114
+
When {% data variables.product.prodname_copilot_chat_short %} provides a response that includes code that matches code in a public {% data variables.product.github %} repository, this is indicated below the suggested code, with a link to display details of the matched code in the output log.
115
+
116
+
{% endvisualstudio %}
117
+
100
118
### How code referencing finds matching code
101
119
102
120
{% data variables.product.prodname_copilot_short %} 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 {% data variables.product.prodname_dotcom_the_website %}. Code in private {% data variables.product.prodname_dotcom %} repositories, or code outside of {% data variables.product.prodname_dotcom %}, 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.
@@ -125,7 +143,7 @@ You can view code references in the log file for your JetBrains IDE.
125
143
The log entry includes the following details:
126
144
127
145
* The date and time you accepted the suggestion.
128
-
* A "Public Code References" message telling you that matching code was found.
146
+
* A "Public Code References" message telling you that similar code was found.
129
147
* The path to the file in which the suggestion was added.
130
148
* The line and column number where the suggestion was added.
131
149
* A list of matches, including:
@@ -134,87 +152,76 @@ The log entry includes the following details:
134
152
135
153
### Verifying the code referencing functionality
136
154
137
-
You can verify that code referencing is working by prompting {% data variables.product.prodname_copilot_short %} to add some commonly used code and checking the output in the log file for your IDE.
138
-
139
-
1. Display the log file for your JetBrains IDE, as described in the previous section.
140
-
1. Create a file called `fizz-buzz.js` and open it in the JetBrains editor.
141
-
1. In the editor, type:
142
-
143
-
```javascript
144
-
functionfizzBuzz()
145
-
```
146
-
147
-
With a space after the closing parenthesis.
148
-
149
-
{% data variables.product.prodname_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 {% data variables.product.github %} website.
150
-
151
-
1. Accept the suggestion by pressing <kbd>Tab</kbd>.
152
-
1. Check whether a "[Public Code References]" entry has been added to the log file.
155
+
{% data reusables.copilot.code-referencing-verifying %}
153
156
154
157
{% endjetbrains %}
155
158
156
159
{% vscode %}
157
160
158
161
## View code references for code completion
159
162
160
-
You can access code references from one of the {% data variables.product.prodname_copilot %} logs in {% data variables.product.prodname_vscode %}.
163
+
You can find code references in one of the {% data variables.product.prodname_copilot %} logs in {% data variables.product.prodname_vscode %}.
161
164
162
165
1. In {% data variables.product.prodname_vscode %}, open the **Output** window by selecting **View** > **Output** from the menu bar.
163
-
1. In the dropdown menu at the right of the **Output** window, select **{% data variables.product.prodname_copilot %} Log**.
164
-
165
-

166
-
167
-
1. Leave the **{% data variables.product.prodname_copilot%} Log** view displayed while you use {% data variables.product.prodname_copilot%} in {% data variables.product.prodname_vscode%}.
166
+
1. In the dropdown menu at the right of the **Output** window, select **{% data variables.product.prodname_copilot %} Log (Code References)**.
167
+
1. Leave the **{% data variables.product.prodname_copilot %} Log (Code References)** view displayed while you use {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vscode %}.
168
168
169
169
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to the log.
170
170
171
171
The log entry includes the following details:
172
172
173
173
* The date and time you accepted the suggestion.
174
174
* The name of the file in which the suggestion was added.
175
-
*A message telling you that similar code was found, withthe number and type of licenses.
176
-
*A link to a page on {% data variables.product.prodname_dotcom_the_website%}.
177
-
* The location inthe file where the suggestion was added.
178
-
*A snippetofpart of the code that was suggested and added.
175
+
*"Similar code at" followed by the location in the file where the suggestion was added.
176
+
*An extract of the code that was added by code completion.
177
+
* The license type for the matching code, if found, otherwise `unknown`.
178
+
*The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the similar code was found.
179
179
180
-

180
+
### Example log entry
181
181
182
-
> [!NOTE] The {% data variables.product.prodname_copilot%} log is flushed when you close the editor.
182
+
```text
183
+
2025-03-27 12:17:54.759 [info] file:///Users/monalisa/fizzbuzz.js Similar code at [Ln 2, Col 8] let i = 1; i <= 100; i++) { let output = ''; if (i % 3 === 0) { output += 'Fizz';...
1. In the log entry, <kbd>Ctrl</kbd>+click (Windows/Linux) or <kbd>Command</kbd>+click (Mac) the link to view the code references on {% data variables.product.prodname_dotcom_the_website%}.
188
+
### Verifying the code referencing functionality
185
189
186
-
The page lists the matches that were found, showing an excerpt from the relevant file. You can click on the file name to view the whole file.
190
+
{% data reusables.copilot.code-referencing-verifying %}
187
191
188
-

192
+
{% endvscode %}
189
193
190
-
Matches may be found in multiple repositories with different, sometimes conflicting, licenses. You can use the checkboxes on the left of the page to show only the matches associated with a particular license.
194
+
{% visualstudio %}
191
195
192
-
You should review all license information within a repository to verify that it applies to the matching code, as repositories may contain multiple licenses and these licenses are subject to human and non-human error.
196
+
## View code references for code completion
193
197
194
-
> [!NOTE] The web page displaying the full set of details will remain available for three months.
198
+
You can find code references in the {% data variables.product.prodname_copilot %} log in {% data variables.product.prodname_vs %}.
195
199
196
-
### Verifying the code referencing functionality
200
+
1. In the menu bar, click **View**.
201
+
1. In the dropdown menu, click **Output**.
202
+
1. In Output view, click the box to the right of "Show output from" and select **{% data variables.product.prodname_copilot %}**.
203
+
1. Leave the log displayed while you use {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vscode %}.
197
204
198
-
You can verify that code referencing is working by prompting {% data variables.product.prodname_copilot_short%} to add some commonly used code and checking the output in the {% data variables.product.prodname_copilot_short%} log.
205
+
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to the log.
199
206
200
-
1. In {% data variables.product.prodname_vscode%}, create a file called `fizz-buzz.js`.
201
-
1. Open the **Output**window by selecting **View**>**Output** from the menu bar.
202
-
1. In the dropdown menu at the right of the **Output**window, select **{% data variables.product.prodname_copilot%} Log**.
203
-
1. In the editor, type:
207
+
The log entry includes the following details:
204
208
205
-
```javascript
206
-
function fizzBuzz()
207
-
```
209
+
* The time you accepted the suggestion. Click the "Show Timestamp" clock icon if the time is not displayed.
210
+
* The description `[Completions Public Code Match Information]`.
211
+
* The license type for the matching code, if found, otherwise `NOASSERTION`.
212
+
* The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the similar code was found.
208
213
209
-
With a space after the closing parenthesis.
214
+
### Example log entry
210
215
211
-
{% data variables.product.prodname_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 {% data variables.product.github %} website.
216
+
```text
217
+
09:39:16:203 [Completions Public Code Match Information] Similar code with license type [MIT] https://github.com/octo-org/octo-repo/blob/34deb75eb6a2e22483ed465a6aec38c02eb2536e/routines/quicksort.js
218
+
```
212
219
213
-
1. Accept the suggestion by pressing <kbd>Tab</kbd>.
220
+
### Verifying the code referencing functionality
214
221
215
-
If code referencing finds a match to public code, a log entry is added to the **{% data variables.product.prodname_copilot %} Log** view.
222
+
{% data reusables.copilot.code-referencing-verifying %}
216
223
217
-
{% endvscode %}
224
+
{% endvisualstudio %}
218
225
219
226
## View code references for {% data variables.product.prodname_copilot_chat_short %}
220
227
@@ -230,6 +237,52 @@ You can verify that code referencing is working by prompting {% data variables.p
230
237
231
238
{% endvscode %}
232
239
240
+
{% visualstudio %}
241
+
242
+
If a response in {% data variables.product.prodname_copilot_chat_short %} includes matching code, this is below the suggested code by the following text:
243
+
244
+
> Found similar code in public repos. **View matches**
245
+
246
+
Click **View matches** to open the {% data variables.product.prodname_copilot %} log, if it is not already open, and add details of the matched code.
247
+
248
+
The details include:
249
+
250
+
* The time you added the details to the log. Click the "Show Timestamp" clock icon if the time is not displayed.
251
+
* The description `[Code Match]` as the first log entry before the list of matching code.
252
+
* The license type—if found—for each instance of similar code.
253
+
* The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the matching code was found.
254
+
* A code snippet showing the matching code.
255
+
256
+
### Logging example
257
+
258
+
```text
259
+
09:24:10:525 [Code Match] Similar code with 2 license type(s) [MIT, NOASSERTION]
When {% data variables.product.prodname_copilot_chat_short %} provides a response that includes code that matches code in a public {% data variables.product.prodname_dotcom %} repository, this is indicated beneath the code suggestion:
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, information about the matching code is logged. 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.
2
+
1
3
> [!NOTE]
2
4
> * Code referencing for code completion only occurs for matches of accepted {% data variables.product.prodname_copilot_short %} suggestions. Code you have written, and {% data variables.product.prodname_copilot_short %} suggestions you have altered, are not checked for matches to public code.
3
5
> * Typically, matches to public code occur in less than one percent of {% data variables.product.prodname_copilot_short %} suggestions, so you should not expect to see code references for many suggestions.
You can verify that code referencing is working by prompting {% data variables.product.prodname_copilot_short %} to add some commonly used code and checking the output in the log.
2
+
3
+
1. Create a file called `fizz-buzz.js` and open it in the editor.
4
+
1. Display the log as described in the previous section.
5
+
1. In the editor, type:
6
+
7
+
```javascript
8
+
functionfizzBuzz()
9
+
```
10
+
11
+
With a space after the closing parenthesis.
12
+
13
+
{% data variables.product.prodname_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 {% data variables.product.github %} website.
14
+
15
+
1. To accept the suggestion, press <kbd>Tab</kbd>.
16
+
1. Check whether any entries for similar code have been added to the log.
0 commit comments