# Search Query Syntax

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

A typical search consists of two parts:

-   A [search pattern](#search-patterns) containing the terms you want to search, for example `println`
-   [Search filters](#filters-all-searches) that scope the search to certain repositories, languages, etc., for example `lang:java`

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

## 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                                                                                                           |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [`foo bar`](https://sourcegraph.com/search?q=foo+bar&patternType=keyword)                                                                       | Match documents containing both `foo` and `bar` anywhere in the document.                                             |
| [`"foo bar"`](https://sourcegraph.com/search?q=%22foo+bar%22&patternType=keyword)                                                               | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched. |
| [`"foo \"bar\""`](https://sourcegraph.com/search?q=context:global+%22foo+%5C%22bar%5C%22%22&patternType=keyword)                                | Match the string `foo "bar"` exactly.                                                                                 |
| [`/foo.*bar/`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+/foo.*bar/&patternType=keyword) | Match the **regular expression** `foo.*bar`. We support [RE2 syntax](https://golang.org/s/re2syntax).                 |
| [`foo OR bar`](https://sourcegraph.com/search?q=context:global+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**                                                                                                                              |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| [`foo bar`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+foo+bar&patternType=regexp)                     | Search for the regexp `foo(.*?)bar`. Spaces between non-whitespace strings becomes `.*?` to create a fuzzy search                            |
| [`foo\ bar`](https://sourcegraph.com/search?q=foo%5C+bar&patternType=regexp) or [`/foo bar/`](https://sourcegraph.com/search?q=/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 |
| [`foo\nbar`](https://sourcegraph.com/search?q=foo%5Cnbar&patternType=regexp)                                                                                 | Perform a multiline regexp search. `\n` is interpreted as a newline                                                                          |
| [`"foo bar"`](https://sourcegraph.com/search?q=%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/myteam/abc` 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:gorilla/mux testroute`](https://sourcegraph.com/search?q=repo:gorilla/mux+testroute) <br/> [`repo:^github\.com/sourcegraph/sourcegraph$@v3.14.0 mux`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24%40v3.14.0+mux&patternType=keyword)                                                                                                   |
| **-repo:regexp-pattern** <br /> _alias: -r_                                                                                                                                                                                                                      | Exclude results from repositories whose path matches the regexp                                                                                                                                                                                                                                                                                                                                                                                      | `repo:alice/ -repo:old-repo`                                                                                                                                                                                                                                                                                                                                                        |
| **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:sourcegraph/sourcegraph rev:v3.14.0 mux`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph+rev:v3.14.0+mux&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$`.                                                                                                                                                                                                                                                                          | [`file:\.js$ httptest`](https://sourcegraph.com/search?q=file:%5C.js%24+httptest) <br /> [`file:internal/ httptest`](https://sourcegraph.com/search?q=file:internal/+httptest)                                                                                                                                                                                                      |
| **-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$`.                                                                                                                                                                                                                                                                               | [`file:\.js$ -file:test http`](https://sourcegraph.com/search?q=file:%5C.js%24+-file:test+http)                                                                                                                                                                                                                                                                                     |
| **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:sourcegraph content:"repo:sourcegraph"`](https://sourcegraph.com/search?q=repo:sourcegraph+content:"repo:sourcegraph"&patternType=keyword)                                                                                                                                                                                                                                   |
| **-content:"pattern"**                                                                                                                                                                                                                                           | Exclude results from files whose content matches the pattern.                                                                                                                                                                                                                                                                                                                                                                                        | [`file:Dockerfile alpine -content:alpine:latest`](https://sourcegraph.com/search?q=file:Dockerfile+alpine+-content:alpine:latest&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                                                                                                                                        | [`fmt.Errorf select:repo`](https://sourcegraph.com/search?q=fmt.Errorf+select:repo&patternType=keyword)                                                                                                                                                                                                                                                                             |
| **language:language-name** <br /> _alias: lang, l_                                                                                                                                                                                                               | Only include results from files in the specified programming language                                                                                                                                                                                                                                                                                                                                                                                | [`language:typescript encoding`](https://sourcegraph.com/search?q=language:typescript+encoding)                                                                                                                                                                                                                                                                                     |
| **-language:language-name** <br /> _alias: -lang, -l_                                                                                                                                                                                                            | Exclude results from files in the specified programming language                                                                                                                                                                                                                                                                                                                                                                                     | [`-language:typescript encoding`](https://sourcegraph.com/search?q=-language:typescript+encoding)                                                                                                                                                                                                                                                                                   |
| **type:symbol**                                                                                                                                                                                                                                                  | Perform a symbol search                                                                                                                                                                                                                                                                                                                                                                                                                              | [`type:symbol path`](https://sourcegraph.com/search?q=type:symbol+path)                                                                                                                                                                                                                                                                                                             |
| **case:yes**                                                                                                                                                                                                                                                     | Perform a case sensitive query. Without this, everything is matched case insensitively                                                                                                                                                                                                                                                                                                                                                               | [`OPEN_FILE case:yes`](https://sourcegraph.com/search?q=OPEN_FILE+case:yes)                                                                                                                                                                                                                                                                                                         |
| **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:sourcegraph`](https://sourcegraph.com/search?q=fork:yes+repo:sourcegraph)                                                                                                                                                                                                                                                                                           |
| **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:sourcegraph/ archived:only`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+archived:only)                                                                                                                                                                                                                                                                 |
| **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:has.path(\.py) file:Dockerfile pip`](https://sourcegraph.com/search?q=context:global+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(code-search) rank`](https://sourcegraph.com/search?q=context:global+repo:sourcegraph/sourcegraph%24+rank&patternType=keyword&sm=1&groupBy=repo)                                                                                                                                                                                                                    |
| **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:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28yesterday%29&patternType=keyword) <br /> [`repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+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.                                                                                                                                                                                                                                                                                                                                                                                               | [`rev:at.time(1 year ago)`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+rev:at.time%281+year+ago%29+&patternType=keyword&sm=0) <br /> [`rev:at.time(2021-01-01)`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+rev:at.time%282021-01-01%2C+v5.0.0%29+&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                                                                                                                                                                                                                                                            | [`file:has.content(Copyright) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.content%28Copyright%29+Sourcegraph&patternType=keyword)                                                                                                                                                                                                                        |
| **file:has.owners(...)**                                                                                                                                                                                                                                         | Conditionally search files only if they are owned by the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more                                                                                                                                                                                                                                                                                            | [`file:has.owner(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.owner%28alice@sourcegraph.com%29+Sourcegraph&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                                                                                                                                                                                                                                                  | [`file:has.contributor(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.owner%28alice@sourcegraph.com%29+Sourcegraph&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**                                                                                                                                                                                                                               | [`count:1000 function`](https://sourcegraph.com/search?q=count:1000+repo:sourcegraph/sourcegraph$+function) <br /> [`count:all err`](https://sourcegraph.com/search?q=repo:github.com/sourcegraph/sourcegraph+err+count:all&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/sourcegraph timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+timeout:15s+func+count:10000)                                                                                                                                                                                                                        |
| **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                                                                                                                                                                                                                                                                     | [`test. patternType:keyword`](https://sourcegraph.com/search?q=test.+patternType:keyword)<br/>[`(open/close)file patternType:regexp`](https://sourcegraph.com/search?q=%28open%7Cclose%29file&patternType=regexp)                                                                                                                                                                   |
| **visibility:any, visibility:public, visibility:private**                                                                                                                                                                                                        | Filter results to only public or private repositories. The default is to include both private and public repositories                                                                                                                                                                                                                                                                                                                                | [`type:repo visibility:public`](https://sourcegraph.com/search?q=type:repo+visibility:public)                                                                                                                                                                                                                                                                                       |

Multiple or combined **repo:** and **file:** filters are intersected. For example, `repo:foo repo:bar` limits your search to repositories whose path contains **both** `foo` and `bar` (such as `github.com/alice/foobar`). To include results from repositories whose path contains **either** `foo` or `bar`, use `repo:foo|bar`.

<Callout type="info">
	The `rev:at.time(...)` filter is only supported for Sourcegraph versions 5.4
	or more.
</Callout>

## Boolean operators

Use boolean operators to create more expressive searches.

| **Operator** | **Example**                                                                                                                                                                                                                                                                                                                                                  |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `and`, `AND` | [`conf.Get( and log15.Error(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+and+log15.Error%28&patternType=regexp), [`conf.Get( and log15.Error( and after`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+and+log15.Error%28+and+after&patternType=regexp) |

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

| **Operator** | **Example**                                                                                                                                                                                                                                                                                                                                                        |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `or`, `OR`   | [`conf.Get( or log15.Error(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+or+log15.Error%28&patternType=regexp), [<code>conf.Get( or log15.Error( or after </code>](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+or+log15.Error%28+or+after&patternType=regexp) |

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:(internal/repos)|(internal/gitserver)`, to receive the expected results use [subexpressions](/code-search/working/search-subexpressions), `(file:internal/repos or file:internal/gitserver)`

| **Operator** | **Example**                                                                                                                                                                                                                                                       |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `not`, `NOT` | [`lang:go not file:main.go panic`](https://sourcegraph.com/search?q=lang:go+not+file:main.go+panic&patternType=keyword), [`panic NOT ever`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%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:vscode@*refs/heads/:^refs/heads/master type:diff task`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/Microsoft/vscode%24%40*refs/heads/:%5Erefs/heads/master+type:diff+after:%221+month+ago%22+task#1) (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).                                                                                                                                                                                                                                                                          | [`type:diff func`](https://sourcegraph.com/search?q=type:diff+func+repo:sourcegraph/sourcegraph$) <br/> [`type:commit test`](https://sourcegraph.com/search?q=type:commit+test+repo:sourcegraph/sourcegraph$)                                                                                     |
| **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._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick)                                                                                                                                                                                   |
| **-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._           | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick)                                                                                                                                                                                   |
| **before:"string specifying time frame"** | Only include results from diffs or commits which have a commit date before the specified time frame                                                                                                                                                                                                                                                                                                                                                                                                                 | [`before:"last thursday"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22last+thursday%22) <br/> [`before:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22november+1+2019%22) |
| **after:"string specifying time frame"**  | Only include results from diffs or commits which have a commit date after the specified time frame                                                                                                                                                                                                                                                                                                                                                                                                                  | [`after:"6 weeks ago"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%226+weeks+ago%22) <br/> [`after:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%22november+1+2019%22)         |
| **message:"any string"**                  | Only include results from diffs or commits which have commit messages containing the string                                                                                                                                                                                                                                                                                                                                                                                                                         | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22) <br/> [`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22)                         |
| **-message:"any string"**                 | Exclude the results from diffs or commits which have commit messages containing the string                                                                                                                                                                                                                                                                                                                                                                                                                          | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22) <br/> [`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22)                         |

## 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/myteam/abc@<revisions>` is equivalent to `repo:github.com/myteam/abc 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:

-   [`@*refs/heads/*`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/docker/machine%24%40*refs/heads/*+middleware&patternType=keyword) - search across all branches
-   [`@*refs/tags/*`](https://sourcegraph.com/search?q=repo:github.com/docker/machine%24%40*refs/tags/*+server&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:

-   [`@*refs/heads/*:*!refs/heads/release* type:commit `](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24%40*refs/heads/*:*%21refs/heads/release*+type:commit+&patternType=keyword) - search commits on all branches except on those that start with "release"
-   [`@*refs/tags/v3.*:*!refs/tags/v3.*-* context`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/sourcegraph%24%40*refs/tags/v3.*:*%21refs/tags/v3.*-*+context&patternType=keyword) - search all versions starting with `3.` 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:docker repo:registry`](https://sourcegraph.com/search?q=repo:docker+repo:registry) matches repositories with names that contain both `docker` and `registry` substrings
-   Example: [`repo:docker OR repo:registry`](https://sourcegraph.com/search?q=repo:docker+OR+repo:registry&patternType=keyword) matches repositories with names that contain either `docker` or `registry` 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/myteam/abc@main:^3.15 type:commit` will show all commits in `main`
minus the commits reachable from the commit tagged with `3.15`.

## Filename Search

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

-   Example: [`type:path repo:/docker/ registry`](https://sourcegraph.com/search?q=type:path+repo:/docker/+registry)

## Content Search

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

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