blob: 0dab3c06c6956605e4b456562d73c60f0b32e453 [file] [log] [blame] [view]
Wendy Wang859617c2025-02-04 16:09:16 +01001# Gitiles API Reference
2
3[TOC]
4
5### Formatting
6
7`?format=`: `TEXT`, `HTML`, and `JSON`
8
9The `JSON` output has a `)]}'` line at the top to prevent cross-site scripting.
10When parsing, strip that line and the rest can be parsed normally.
11
12#### URL Format
13Depending on the servlet context path set up to serve gitiles, the URL used to access these end points may differ.
14
15On gerrit.googlesource.com one URL is: `https://gerrit.googlesource.com/a/gitiles/+refs?format=TEXT`, while for a standard localhost deployment, the equivalent URL would be `http://localhost:8080/a/plugins/gitiles/test+refs?format=TEXT`. The examples given in this document are of the former form, to allow testing against real refs. They require authentication described in [the REST API Developer's Notes](https://gerrit-review.googlesource.com/Documentation/dev-rest-api.html).
16
17### Endpoints
18
19#### **`+refs`**
20`https://gerrit.googlesource.com/a/gitiles/+refs?format=TEXT`
21
22Lists all refs (branches, tags, etc.) in the repository.
23
24#### **`+log`**
25`https://gerrit.googlesource.com/a/gitiles/+log/refs/heads/master?n=10&format=JSON`
26
27Shows the commit log.
28Use the parameter `n=<number>` to limit the number of commits returned.
29For paging use the start parameter `s=<next_cursor>`.
30The `next` key in the JSON provides a cursor for the next page. Use it with `s=<next_cursor>`.
31The final page will have no `next` key.
32Every page except for the first will have a `previous` cursor to page backwards.
33
34#### **`+show`**
35`https://gerrit.googlesource.com/a/gitiles/+show/refs/heads/master/?format=JSON`
36
37View the metadata about a given target. If the target is a file, use `format=TEXT` to view base64-encoded content, e.g.
38```bash
39curl "https://gerrit.googlesource.com/a/gitiles/+show/refs/heads/master/README.md?format=TEXT" | base64 -d
40```
41
42#### **`+archive`**
43`https://gerrit.googlesource.com/a/gitiles/+archive/refs/heads/master.tar.gz`
44
45Download a compressed archive of a repository at a specific commit or ref.
46Supported formats: `.tar.gz` and `.zip`
47```bash
48curl "https://gerrit.googlesource.com/a/gitiles/+archive/refs/heads/master.tar.gz" -o repo.tar.gz
49```
50
51#### **`+doc`**
52`https://gerrit.googlesource.com/a/gitiles/+doc/refs/heads/master/README.md`
53
54Renders Markdown files into HTML.
55
56#### **`+blame`**
57`https://gerrit.googlesource.com/a/gitiles/+blame/refs/heads/master/README.md`
58
59Shows line-by-line author information for a specific file (`git blame`).
60
61#### **`+diff`**
62`https://gerrit.googlesource.com/a/gitiles/+diff/refs/heads/master/?from=master~1&to=master`
63
64Compute the diff between two commits.