blob: 99ee0ee5da872f2952014f67732c5a507742ebf8 [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
Matthias Sohn38a4daf2025-06-24 15:50:29 +020049curl "https://gerrit.googlesource.com/a/gitiles/+archive/30851aacbea3370c7be8179c890b3401526242eb.tar.gz" -o repo.tar.gz
50```
51
52Download a compressed archive of a folder `java/com/google/gitiles/dev/` in a repository at a specific commit or ref.
53```bash
54curl "https://gerrit.googlesource.com/a/gitiles/+/refs/heads/master/java/com/google/gitiles/dev.tar.gz" -o dev.tar.gz
55curl "https://gerrit.googlesource.com/a/gitiles/+/30851aacbea3370c7be8179c890b3401526242eb/java/com/google/gitiles/dev.tar.gz" -o dev.tar.gz
Wendy Wang859617c2025-02-04 16:09:16 +010056```
57
58#### **`+doc`**
59`https://gerrit.googlesource.com/a/gitiles/+doc/refs/heads/master/README.md`
60
61Renders Markdown files into HTML.
62
63#### **`+blame`**
64`https://gerrit.googlesource.com/a/gitiles/+blame/refs/heads/master/README.md`
65
66Shows line-by-line author information for a specific file (`git blame`).
67
68#### **`+diff`**
69`https://gerrit.googlesource.com/a/gitiles/+diff/refs/heads/master/?from=master~1&to=master`
70
71Compute the diff between two commits.