# Search Query Syntax

<p className="subtitle">
	This page describes the query syntax for Code Search.
</p>

A typical search combines a [search pattern](#search-patterns), the terms you want to find, with [search filters](#filters-all-searches) that limit where Sourcegraph looks. Filters and patterns can appear in any order.

For a graphical view of Sourcegraph's query syntax, see the [search language reference](/code-search/queries/language).

## Quick reference

Most queries combine up to four parts:

1. **Scope**: choose the repositories to search, for example `repo:^github\.com/kubernetes/kubernetes$`.
2. **Narrow**: filter by language, file path, or result type, for example `lang:go -file:_test\.go$`.
3. **Version**: choose a branch, tag, or commit, for example `rev:release-1.33`.
4. **Find**: describe what to match, for example `"feature gate"`.

[`repo:^github\.com/kubernetes/kubernetes$ lang:go -file:_test\.go$ rev:release-1.33 "feature gate"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+lang:go+-file:_test%5C.go%24+rev:release-1.33+%22feature+gate%22&patternType=keyword)

The examples on this page search public repositories on Sourcegraph.com, mostly [kubernetes/kubernetes](https://github.com/kubernetes/kubernetes) and [microsoft/vscode](https://github.com/microsoft/vscode). To search your own code, change the `repo:` filter.

### Find code

- Files that contain all terms, in any order:\
  [`repo:^github\.com/kubernetes/kubernetes$ kubelet eviction`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+kubelet+eviction&patternType=keyword)
- An exact phrase:\
  [`repo:^github\.com/kubernetes/kubernetes$ "failed to sync pod"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22failed+to+sync+pod%22&patternType=keyword)
- A regular expression:\
  [`repo:^github\.com/kubernetes/kubernetes$ /eviction.*threshold/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/eviction.*threshold/&patternType=keyword)
- A combination of terms:\
  [`repo:^github\.com/kubernetes/kubernetes$ (error OR warning) AND retry NOT deprecated`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%28error+OR+warning%29+AND+retry+NOT+deprecated&patternType=keyword)
- Text in exactly this case:\
  [`repo:^github\.com/kubernetes/kubernetes$ PodSpec case:yes`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+PodSpec+case:yes&patternType=keyword)

### Narrow the search

- One repository:\
  [`repo:^github\.com/kubernetes/kubernetes$`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24&patternType=keyword)
- Repositories that match a pattern, except some:\
  [`repo:^github\.com/kubernetes/ -repo:kubernetes/website`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+-repo:kubernetes/website&patternType=keyword)
- Files in repositories that contain a path:\
  [`repo:^github\.com/kubernetes/ repo:has.path(\.py) file:Dockerfile`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28%5C.py%29+file:Dockerfile&patternType=keyword)
- Repositories with recent commits:\
  [`repo:^github\.com/kubernetes/ repo:has.commit.after(1 month ago)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%281+month+ago%29&patternType=keyword)
- One language:\
  [`repo:^github\.com/microsoft/vscode$ lang:typescript registerCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+lang:typescript+registerCommand&patternType=keyword)
- All languages except one:\
  [`repo:^github\.com/kubernetes/kubernetes$ "feature gate" -lang:markdown`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22feature+gate%22+-lang:markdown&patternType=keyword)
- Symbol definitions:\
  [`repo:^github\.com/kubernetes/kubernetes$ type:symbol NewKubeletCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:symbol+NewKubeletCommand&patternType=keyword)
- Files with an extension that contain a pattern:\
  [`repo:^github\.com/kubernetes/kubernetes$ file:\.go$ file:has.content(TODO)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.go%24+file:has.content%28TODO%29&patternType=keyword)

`repo:` and `file:` take regular expressions, so `repo:kubernetes/kubernetes` also matches `kubernetes/kubernetes-template-project`. Use `^` and `$` to match one repository. The argument of `file:has.content(...)` is also a regular expression, and quotes in it are matched literally: `file:has.content("TODO")` matches only files that contain `"TODO"` with the quotes.

Sourcegraph combines filters with `AND`, so you don't need an operator between them. For example, to find `authentication failed` in Node.js repositories in the `microsoft` organization, excluding generated and vendored code:

[`repo:^github\.com/microsoft/ repo:has.path(package.json) -file:(generated|vendor|dist|node_modules) "authentication failed"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/+repo:has.path%28package.json%29+-file:%28generated%7Cvendor%7Cdist%7Cnode_modules%29+%22authentication+failed%22&patternType=keyword)

To list recently active Go repositories in the `kubernetes` organization that contain a Dockerfile:

[`repo:^github\.com/kubernetes/ repo:has.path(Dockerfile) repo:has.commit.after(3 months ago) lang:go select:repo`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28Dockerfile%29+repo:has.commit.after%283+months+ago%29+lang:go+select:repo&patternType=keyword)

### Search branches and tags

Sourcegraph searches each repository's default branch unless the query has a `rev:` filter. A `rev:` filter needs a `repo:` filter in the same query. On its own, a query such as `rev:release-1.33` returns an `Invalid syntax` alert that asks for a `repo:` filter.

- A branch, tag, or commit:\
  [`repo:^github\.com/kubernetes/kubernetes$ rev:release-1.33 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:release-1.33+kubelet&patternType=keyword)
- The default branch:\
  [`repo:^github\.com/kubernetes/kubernetes$ rev:HEAD kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:HEAD+kubelet&patternType=keyword)
- All branches:\
  [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/heads/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/heads/*+kubelet&patternType=keyword)
- All tags:\
  [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/tags/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/tags/*+kubelet&patternType=keyword)

If some repositories that match `repo:` don't have the revision, Sourcegraph searches the others and lists the missing revisions under **Some revisions could not be searched**. For example, most repositories in the `kubernetes` organization don't have a `release-1.33` branch:

[`repo:^github\.com/kubernetes/ rev:release-1.33 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+rev:release-1.33+kubelet&patternType=keyword)

To search several revisions at once, exclude branches, or use commit hashes, see [repository revisions](#repository-revisions).

### Saved scopes and large searches

- [Search contexts](/code-search/working/search-contexts) save a set of repositories and revisions. Select one with `context:`, for example `context:global`, which searches all repositories on the instance.
- [Search Jobs](/code-search/types/search-jobs) run a search in the background across many repositories, branches, or very large result sets, without the timeouts and result limits of interactive search, then let you download the results.

## Search patterns

This section documents the search pattern syntax in Sourcegraph. To match file content, you need to specify a search pattern. Search patterns are optional when searching [commits](#filters-diff-and-commit-searches-only), [filenames](#filename-search), or [repository names](#repository-name-search).

### Keyword search (default)

Keyword search matches individual terms anywhere in the document or the filename. Use `"..."` to match phrases exactly. Specify regular expressions inside `/.../`.

| Search pattern syntax                                                                                                                                                                     | Description                                                                                                           |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [`repo:^github\.com/kubernetes/kubernetes$ foo bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo+bar&patternType=keyword)                         | Match documents containing both `foo` and `bar` anywhere in the document.                                             |
| [`repo:^github\.com/kubernetes/kubernetes$ "foo bar"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22foo+bar%22&patternType=keyword)                 | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched. |
| [`repo:^github\.com/kubernetes/kubernetes$ "foo \"bar\""`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22foo+%5C%22bar%5C%22%22&patternType=keyword) | Match the string `foo "bar"` exactly.                                                                                 |
| [`repo:^github\.com/kubernetes/kubernetes$ /foo.*bar/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/foo.*bar/&patternType=keyword)                   | Match the **regular expression** `foo.*bar`. We support [RE2 syntax](https://golang.org/s/re2syntax).                 |
| [`repo:^github\.com/kubernetes/kubernetes$ foo OR bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo+OR+bar&patternType=keyword)                   | Match documents containing `foo` _or_ `bar` anywhere in the document.                                                 |

<Callout type="tip">
	Matching is case-insensitive by default (toggle the `Aa` button to change).
</Callout>
<Callout type="note">
	In version 5.4, `keyword` replaced `standard` as the new default pattern
	type.
</Callout>

### Regular expression search

Clicking the (.\*) toggle interprets all search patterns as regular expressions.

<Callout type="note">
	{' '}
	In [Keyword search](#keyword-search-default), use `/.../` to perform regular
	expression searches. Use this mode if you prefer writing out regular
	expressions without enclosing them. In this mode spaces between patterns
	mean **match anything**. Patterns inside quotes mean **match exactly**.
</Callout>

| **Search Syntax**                                                                                                                                                                                                                                                                                                                            | **Description**                                                                                                                              |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| [`repo:^github\.com/kubernetes/kubernetes$ foo bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo+bar&patternType=regexp)                                                                                                                                                                             | Search for the regexp `foo(.*?)bar`. Spaces between non-whitespace strings becomes `.*?` to create a fuzzy search                            |
| [`repo:^github\.com/kubernetes/kubernetes$ foo\ bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo%5C+bar&patternType=regexp) or [`repo:^github\.com/kubernetes/kubernetes$ /foo bar/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/foo+bar/&patternType=regexp) | Search for the regexp `foo bar`. The `\` escapes the space and treats the space as part of the pattern. Use `/.../` to avoid escaping spaces |
| [`repo:^github\.com/kubernetes/kubernetes$ foo\nbar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo%5Cnbar&patternType=regexp)                                                                                                                                                                         | Perform a multiline regexp search. `\n` is interpreted as a newline                                                                          |
| [`repo:^github\.com/kubernetes/kubernetes$ "foo bar"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22foo+bar%22&patternType=regexp)                                                                                                                                                                     | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched.                        |

<Callout type="note">
	We support [RE2 syntax](https://golang.org/s/re2syntax). Matching is
	case-insensitive by default (toggle the `Aa` button to change).
</Callout>

## Filters (all searches)

The following filters can be used on all searches (using [RE2 syntax](https://golang.org/s/re2syntax) any place a regex is accepted):

| **Filters**                                                                                                                                                                                                                                                      | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                      | **Examples**                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **repo:regexp-pattern** <br /> **repo:regexp-pattern@rev** <br /> **repo:regexp-pattern rev:rev**<br />_alias: r_                                                                                                                                                | Include results from repos whose path matches a specified regexp-pattern. The repo path is `github.com/kubernetes/kubernetes` or `code.example.com/xyz` depending on your repo host. If the regexp ends in `@rev`, search that revision instead of the default `main` branch. `repo:regexp-pattern@rev` is equivalent to `repo:regexp-pattern rev:rev`                                                                                               | [`repo:^github\.com/kubernetes/kubernetes$ kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+kubelet&patternType=keyword) <br/> [`repo:^github\.com/kubernetes/kubernetes$@v1.31.0 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@v1.31.0+kubelet&patternType=keyword)                                                                                                                      |
| **-repo:regexp-pattern** <br /> _alias: -r_                                                                                                                                                                                                                      | Exclude results from repositories whose path matches the regexp                                                                                                                                                                                                                                                                                                                                                                                      | [`repo:^github\.com/kubernetes/ -repo:kubernetes/website kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+-repo:kubernetes/website+kubelet&patternType=keyword)                                                                                                                                                                                                                                                                                    |
| **rev:revision-pattern** <br /> _alias: revision_                                                                                                                                                                                                                | Search a revision instead of the default branch. `rev:` can only be used in conjunction with `repo:` and may not be used more than once. See our [revision syntax](#repository-revisions) documentation to learn more                                                                                                                                                                                                                                | [`repo:^github\.com/kubernetes/kubernetes$ rev:v1.31.0 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:v1.31.0+kubelet&patternType=keyword)                                                                                                                                                                                                                                                                                      |
| **file:regexp-pattern** <br /> _alias: f_                                                                                                                                                                                                                        | Only include file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`.                                                                                                                                                                                                                                                                          | [`repo:^github\.com/kubernetes/kubernetes$ file:\.sh$ kubectl`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.sh%24+kubectl&patternType=keyword) <br /> [`repo:^github\.com/kubernetes/kubernetes$ file:pkg/kubelet/ httptest`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:pkg/kubelet/+httptest&patternType=keyword)                                                                     |
| **-file:regexp-pattern** <br /> _alias: -f_                                                                                                                                                                                                                      | Exclude file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`.                                                                                                                                                                                                                                                                               | [`repo:^github\.com/kubernetes/kubernetes$ file:\.go$ -file:_test\.go$ httptest`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.go%24+-file:_test%5C.go%24+httptest&patternType=keyword)                                                                                                                                                                                                                                            |
| **content:"pattern"**                                                                                                                                                                                                                                            | Set the search pattern with a dedicated parameter. Useful when searching literally for a string that may conflict with the [search pattern syntax](#search-pattern-syntax). In between the quotes, the `\` character will need to be escaped (`\\` to evaluate for `\`)                                                                                                                                                                              | [`repo:^github\.com/kubernetes/kubernetes$ content:"repo:"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+content:%22repo:%22&patternType=keyword)                                                                                                                                                                                                                                                                                          |
| **-content:"pattern"**                                                                                                                                                                                                                                           | Exclude results from files whose content matches the pattern.                                                                                                                                                                                                                                                                                                                                                                                        | [`repo:^github\.com/kubernetes/kubernetes$ file:Dockerfile FROM -content:golang`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:Dockerfile+FROM+-content:golang&patternType=keyword)                                                                                                                                                                                                                                                    |
| **select:_result-type_** <br /> **select:repo** <br /> **select:commit.diff.added** <br /> **select:commit.diff.removed** <br /> **select:file** <br /> **select:content** <br /> **select:symbol._symbol-type_** <br /> **select:file.owners** _(Experimental)_ | Shows only query results for a given type. For example, `select:repo` displays only distinct repository paths from search results, and `select:commit.diff.added` shows only added code matching the search. See [language definition](/code-search/queries/language#select) for full list of possible values                                                                                                                                        | [`repo:^github\.com/kubernetes/ fmt.Errorf select:repo`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+fmt.Errorf+select:repo&patternType=keyword)                                                                                                                                                                                                                                                                                                        |
| **language:language-name** <br /> _alias: lang, l_                                                                                                                                                                                                               | Only include results from files in the specified programming language                                                                                                                                                                                                                                                                                                                                                                                | [`repo:^github\.com/microsoft/vscode$ language:typescript encoding`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+language:typescript+encoding&patternType=keyword)                                                                                                                                                                                                                                                                              |
| **-language:language-name** <br /> _alias: -lang, -l_                                                                                                                                                                                                            | Exclude results from files in the specified programming language                                                                                                                                                                                                                                                                                                                                                                                     | [`repo:^github\.com/microsoft/vscode$ -language:typescript encoding`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+-language:typescript+encoding&patternType=keyword)                                                                                                                                                                                                                                                                            |
| **type:symbol**                                                                                                                                                                                                                                                  | Perform a symbol search                                                                                                                                                                                                                                                                                                                                                                                                                              | [`repo:^github\.com/kubernetes/kubernetes$ type:symbol path`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:symbol+path&patternType=keyword)                                                                                                                                                                                                                                                                                            |
| **case:yes**                                                                                                                                                                                                                                                     | Perform a case sensitive query. Without this, everything is matched case insensitively                                                                                                                                                                                                                                                                                                                                                               | [`repo:^github\.com/kubernetes/kubernetes$ KUBECONFIG case:yes`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+KUBECONFIG+case:yes&patternType=keyword)                                                                                                                                                                                                                                                                                      |
| **fork:yes, fork:only**                                                                                                                                                                                                                                          | Include results from repository forks or filter results to only repository forks. Results in repository forks are excluded by default                                                                                                                                                                                                                                                                                                                | [`fork:yes repo:qemu`](https://sourcegraph.com/search?q=fork:yes+repo:qemu&patternType=keyword)                                                                                                                                                                                                                                                                                                                                                                                |
| **archived:yes, archived:only**                                                                                                                                                                                                                                  | The yes option, includes archived repositories. The only option, filters results to only archived repositories. Results in archived repositories are excluded by default                                                                                                                                                                                                                                                                             | [`repo:^github\.com/kubernetes/ archived:only`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+archived:only&patternType=keyword)                                                                                                                                                                                                                                                                                                                          |
| **repo:has.meta(...)**                                                                                                                                                                                                                                           | Conditionally search inside repositories only if they are associated with a specified metadata: <br /> 1. key-value pair, or<br /> 2. key with any value, or <br />3. key with no value <br />See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more                                                                                                                                                              | 1. `repo:has.meta(owning-team:security)` <br /> 2. `repo:has.meta(owning-team)` <br /> 3. `repo:has.meta(archived:)`                                                                                                                                                                                                                                                                                                                                                           |
| **repo:has.path(...)**                                                                                                                                                                                                                                           | Conditionally search inside repositories only if they contain a file path matching the regular expression. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more                                                                                                                                                                                                                                                 | [`repo:^github\.com/kubernetes/ repo:has.path(\.py) file:Dockerfile pip`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28%5C.py%29+file:Dockerfile+pip&patternType=keyword)                                                                                                                                                                                                                                                                |
| **repo:has.topic(...)**                                                                                                                                                                                                                                          | Search only in repos repositories if they have the given GitHub or GitLab topic. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more                                                                                                                                                                                                                                                                           | [`repo:has.topic(kubernetes) kubelet`](https://sourcegraph.com/search?q=repo:has.topic%28kubernetes%29+kubelet&patternType=keyword)                                                                                                                                                                                                                                                                                                                                            |
| **repo:has.commit.after(...)**                                                                                                                                                                                                                                   | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more                                                                                                                                                                                                                                                                    | [`repo:^github\.com/kubernetes/ repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28yesterday%29&patternType=keyword) <br /> [`repo:^github\.com/kubernetes/ repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28june+25+2017%29&patternType=keyword)                                                                   |
| **rev:at.time(...)**                                                                                                                                                                                                                                             | Search a repo or a branch at a specific point in time. Requires a `repo:` filter. The optional second argument is the revision to start from.                                                                                                                                                                                                                                                                                                        | [`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(1 year ago) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%281+year+ago%29+kubelet&patternType=keyword) <br /> [`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(2024-01-01, release-1.29) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%282024-01-01,+release-1.29%29+kubelet&patternType=keyword) |
| **file:has.content(...)**                                                                                                                                                                                                                                        | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more                                                                                                                                                                                                                                                            | [`repo:^github\.com/kubernetes/kubernetes$ file:has.content(Copyright) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.content%28Copyright%29+kubelet&patternType=keyword)                                                                                                                                                                                                                                                  |
| **file:has.owner(...)**                                                                                                                                                                                                                                          | Conditionally search files only if the repository's CODEOWNERS file assigns them to the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more                                                                                                                                                                                                                                                           | [`repo:^github\.com/grafana/grafana$ file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword)                                                                                                                                                                                                              |
| **file:has.contributor(...)**                                                                                                                                                                                                                                    | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more                                                                                                                                                                                                                                                  | [`repo:^github\.com/kubernetes/kubernetes$ file:has.contributor(google\.com) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.contributor%28google%5C.com%29+kubelet&patternType=keyword)                                                                                                                                                                                                                                    |
| **count:_N_,< /> count:all**                                                                                                                                                                                                                                     | Retrieve <em>N</em> results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all**                                                                                                                                                                                                                               | [`repo:^github\.com/kubernetes/kubernetes$ count:1000 function`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:1000+function&patternType=keyword) <br /> [`repo:^github\.com/kubernetes/kubernetes$ count:all err`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:all+err&patternType=keyword)                                                                                                 |
| **timeout:_go-duration-value_**                                                                                                                                                                                                                                  | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github\.com/kubernetes/ timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+timeout:15s+func+count:10000&patternType=keyword)                                                                                                                                                                                                                                                                                            |
| **patterntype:keyword, patterntype:regexp**                                                                                                                                                                                                                      | Configure your query to be interpreted as a keyword search, or a regular expression. Note: this filter is available as an accessibility option in addition to the visual toggles                                                                                                                                                                                                                                                                     | [`repo:^github\.com/kubernetes/kubernetes$ test. patternType:keyword`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+test.+patternType:keyword&patternType=keyword)<br/>[`repo:^github\.com/kubernetes/kubernetes$ (open\|close)file patternType:regexp`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%28open%7Cclose%29file+patternType:regexp&patternType=keyword)                                     |
| **visibility:any, visibility:public, visibility:private**                                                                                                                                                                                                        | Filter results to only public or private repositories. The default is to include both private and public repositories                                                                                                                                                                                                                                                                                                                                | [`repo:^github\.com/kubernetes/ type:repo visibility:public`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+type:repo+visibility:public&patternType=keyword)                                                                                                                                                                                                                                                                                              |

Multiple or combined **repo:** and **file:** filters are intersected. For example, `repo:kubernetes repo:client` limits your search to repositories whose path contains **both** `kubernetes` and `client` (such as `github.com/kubernetes-client/csharp`). To include results from repositories whose path contains **either** pattern, use `|`, for example `repo:kubernetes/kubernetes$|microsoft/vscode$`.

## Boolean operators

Use boolean operators to create more expressive searches.

| **Operator** | **Example**                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `and`, `AND` | [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( and context.WithTimeout(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+and+context.WithTimeout%28&patternType=keyword), [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( and context.WithTimeout( and retry`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+and+context.WithTimeout%28+and+retry&patternType=keyword) |

Returns results for files containing matches on the left _and_ right side of the `and` (set intersection).

| **Operator** | **Example**                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `or`, `OR`   | [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( or context.WithTimeout(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+or+context.WithTimeout%28&patternType=keyword), [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( or context.WithTimeout( or retry`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+or+context.WithTimeout%28+or+retry&patternType=keyword) |

Returns file content matching either on the left or right side, or both (set union). The number of results reports the number of matches of both strings. Note the regex or operator `|` may not work as expected with certain operators for example `file:(pkg/kubelet)|(pkg/scheduler)`, to receive the expected results use [subexpressions](/code-search/working/search-subexpressions), `(file:pkg/kubelet or file:pkg/scheduler)`

| **Operator** | **Example**                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `not`, `NOT` | [`repo:^github\.com/kubernetes/kubernetes$ lang:go not file:main.go panic`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+lang:go+not+file:main.go+panic&patternType=keyword), [`repo:^github\.com/kubernetes/kubernetes$ panic NOT ever`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+panic+NOT+ever&patternType=keyword) |

`NOT` can be used in place of `-` to negate filters, such as `file`, `content`, `lang`, `repohasfile`, and `repo`. For
search patterns, `NOT` excludes documents that contain the term after `NOT`. For readability, you can also include the
`AND` operator before a `NOT` (i.e. `panic NOT ever` is equivalent to `panic AND NOT ever`).

<Callout type="note">
	{' '}
	If you want to search for reserved keywords like `OR` in your code use
	`content` like this: `content:"query with OR"`.
</Callout>

### Operator precedence and groups

Operators may be combined. `and` expressions have higher precedence (bind tighter) than `or` expressions so that `a and b or c and d` means `(a and b) or (c and d)`.

Expressions may be grouped with parentheses to change the default precedence and meaning. For example: `a and (b or c) and d`.

### Filter scope

When parentheses are absent, we use the convention that operators divide
sequences of terms that should be grouped together. That is:

`file:main.c char c or (int i and int j)` generally means `(file:main.c char c) or (int i and int
j)`

To apply the scope of the `file` filter to the entire subexpression, fully group the subexpression:

`file:main.c (char c or (int i and int j))`.

<Callout type="tip">
	Browse the [search subexpressions
	examples](/code-search/working/search-subexpressions) to learn more about
	use cases.
</Callout>

## Filters (diff and commit searches only)

The following filters are only used for **commit diff** and **commit message** searches, which show changes over time:

| **Filter**                                | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | **Examples**                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **repo:regexp-pattern@rev**               | Specifies which Git revisions to search for commits. See our [repository revisions](#repository-revisions) documentation to learn more about the revision syntax.                                                                                                                                                                                                                                                                                                                                                   | [`repo:^github\.com/microsoft/vscode$@*refs/heads/:^refs/heads/main type:diff after:"1 month ago" task`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24@*refs/heads/:%5Erefs/heads/main+type:diff+after:%221+month+ago%22+task&patternType=keyword) (unmerged commit diffs containing `task`)                                                                                                                                                             |
| **type:diff** <br/> **type:commit**       | Specifies the type of search. By default, searches are executed on all code at a given point in time (a branch or a commit). Specify the `type:` if you want to search over changes to code or commit messages instead (diffs or commits).                                                                                                                                                                                                                                                                          | [`repo:^github\.com/kubernetes/kubernetes$ type:diff func`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:diff+func&patternType=keyword) <br/> [`repo:^github\.com/kubernetes/kubernetes$ type:commit test`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+test&patternType=keyword)                                                                                                             |
| **author:name**                           | Only include results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name <user@example.com>`, so to include only authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.<br/><br/> You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`repo:^github\.com/kubernetes/kubernetes$ type:commit author:k8s-ci-robot`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+author:k8s-ci-robot&patternType=keyword)                                                                                                                                                                                                                                                                     |
| **-author:name**                          | Exclude results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name <user@example.com>`, so to exclude authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.<br/><br/> You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._           | [`repo:^github\.com/kubernetes/kubernetes$ type:commit -author:k8s-ci-robot`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+-author:k8s-ci-robot&patternType=keyword)                                                                                                                                                                                                                                                                   |
| **before:"string specifying time frame"** | Only include results from diffs or commits which have a commit date before the specified time frame                                                                                                                                                                                                                                                                                                                                                                                                                 | [`repo:^github\.com/kubernetes/kubernetes$ type:commit before:"last thursday"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+before:%22last+thursday%22&patternType=keyword) <br/> [`repo:^github\.com/kubernetes/kubernetes$ type:commit before:"november 1 2019"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+before:%22november+1+2019%22&patternType=keyword)                     |
| **after:"string specifying time frame"**  | Only include results from diffs or commits which have a commit date after the specified time frame                                                                                                                                                                                                                                                                                                                                                                                                                  | [`repo:^github\.com/kubernetes/kubernetes$ type:commit after:"6 weeks ago"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+after:%226+weeks+ago%22&patternType=keyword) <br/> [`repo:^github\.com/kubernetes/kubernetes$ type:commit after:"november 1 2019"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+after:%22november+1+2019%22&patternType=keyword)                             |
| **message:"any string"**                  | Only include results from diffs or commits which have commit messages containing the string                                                                                                                                                                                                                                                                                                                                                                                                                         | [`repo:^github\.com/kubernetes/kubernetes$ type:commit message:"testing"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+message:%22testing%22&patternType=keyword) <br/> [`repo:^github\.com/kubernetes/kubernetes$ type:diff message:"testing"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:diff+message:%22testing%22&patternType=keyword)                                                 |
| **-message:"any string"**                 | Exclude the results from diffs or commits which have commit messages containing the string                                                                                                                                                                                                                                                                                                                                                                                                                          | [`repo:^github\.com/kubernetes/kubernetes$ type:commit -message:"Merge pull request"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+-message:%22Merge+pull+request%22&patternType=keyword) <br/> [`repo:^github\.com/kubernetes/kubernetes$ type:diff -message:"Merge pull request"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:diff+-message:%22Merge+pull+request%22&patternType=keyword) |

## Repository Search

### Repository Revisions

To search revisions other than the default branch, specify the revisions by either appending them to the
`repo:` filter or by listing them separately with the `rev:` filter. This means: `repo:github.com/kubernetes/kubernetes@<revisions>` is equivalent to `repo:github.com/kubernetes/kubernetes rev:<revisions>`.

The `<revisions>` part refers to repository
revisions (branches, commit hashes, and tags) and may take on the following forms:

(All examples apply to `@` as well as `rev:`)

- `@branch` - a branch name
- `@1735d48` - a commit hash
- `@3.15` - a tag

You can separate revisions by a colon to search multiple revisions at the same time, `@branch:1735d48:3.15`.

Per default, we match revisions to tags, branches, and commits. You can limit the search to branches or tags by adding
the prefix `refs/tags` or `refs/heads`. For example `@refs/tags/3.18` will search the commit tagged
with `3.18`, but not a branch called `3.18` and vice versa for `@refs/heads/3.18`.

**Glob patterns** allow you to search over a range of branches or tags. Prepend `*` to mark a revision
as glob pattern and add the glob-pattern after it like this `repo:<repo>@*<glob-pattern>`. For example:

- [`repo:^github\.com/kubernetes/kubernetes$@*refs/heads/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/heads/*+kubelet&patternType=keyword) - search across all branches
- [`repo:^github\.com/kubernetes/kubernetes$@*refs/tags/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/tags/*+kubelet&patternType=keyword) - search across all tags

We automatically add a trailing `/*` if it is missing from the glob pattern.

You can negate a glob pattern by prepending `*!`, for example:

- [`repo:^github\.com/kubernetes/kubernetes$@*refs/heads/*:*!refs/heads/release* type:commit`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/heads/*:*!refs/heads/release*+type:commit&patternType=keyword) - search commits on all branches except on those that start with "release"
- [`repo:^github\.com/kubernetes/kubernetes$@*refs/tags/v1.31.*:*!refs/tags/v1.31.*-* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/tags/v1.31.*:*!refs/tags/v1.31.*-*+kubelet&patternType=keyword) - search all `v1.31.` versions except release candidates, alpha, and beta versions.

### Repository names

A query with only `repo:` filters returns a list of repositories with matching names.

- Example: [`repo:kubernetes repo:client`](https://sourcegraph.com/search?q=repo:kubernetes+repo:client&patternType=keyword) matches repositories with names that contain both `kubernetes` and `client` substrings
- Example: [`repo:kubernetes OR repo:vscode`](https://sourcegraph.com/search?q=repo:kubernetes+OR+repo:vscode&patternType=keyword) matches repositories with names that contain either `kubernetes` or `vscode` substrings

### Commit and Diff searches

Commit and diff searches act on sets of commits. A set is defined by a revision (branch, commit hash, or tag), and it
contains all commits reachable from that revision. A commit is reachable from another commit if it can be
reached by following the pointers to parent commits.

For commit and diff searches it is possible to exclude a set of commits by prepending a caret `^`. The caret acts as a set
difference. For example, `repo:^github\.com/kubernetes/kubernetes$@release-1.33:^v1.33.0 type:commit` shows all commits in `release-1.33`
minus the commits reachable from the commit tagged with `v1.33.0`.

## Filename Search

A query with `type:path` restricts terms to matching filenames only (not file contents).

- Example: [`repo:^github\.com/kubernetes/kubernetes$ type:path kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:path+kubelet&patternType=keyword)

## Content Search

A query with `type:file` restricts terms to matching file contents only (not filenames).

- Example: [`repo:^github\.com/kubernetes/kubernetes$ type:file kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:file+kubelet&patternType=keyword)
