Commits对比
GET /api/v5/repos/{owner}/{repo}/compare/{base}...{head}
该接口用于查询指定仓库中两个提交之间的对比结果,支持以 Commit SHA、分支名或标签名作为对比起点与终点,返回对比范围内的提交列表、变更文件及增删行数等详细信息。
访问令牌支持说明
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问
此接口允许匿名访问
请求参数
| 参数名 |
位置 |
类型 |
必填 |
说明 |
owner |
path |
string |
是 |
仓库所属空间地址(企业、组织或个人的地址 path) |
repo |
path |
string |
是 |
仓库路径(path) |
base |
path |
string |
是 |
对比的起点。Commit SHA、分支名或标签名 |
head |
path |
string |
是 |
对比的终点。Commit SHA、分支名或标签名 |
straight |
query |
boolean |
否 |
是否直对比,默认 false |
suffix |
query |
string |
否 |
按照文件后缀过滤文件,如 .txt,只影响 files |
响应参数
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit |
object |
是 |
否 |
对比的起点 commit |
merge_base_commit |
object |
是 |
否 |
合并基点(merge base)commit |
commits |
object[] |
是 |
否 |
对比范围内的提交列表 |
files |
object[] |
是 |
否 |
变更文件列表 |
truncated |
integer |
是 |
否 |
响应是否被截断(0/1) |
base_commit 对象(merge_base_commit 结构与之相同)
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit.url |
string |
是 |
否 |
提交的 API 地址 |
base_commit.sha |
string |
是 |
否 |
提交 SHA |
base_commit.html_url |
string |
是 |
否 |
提交的页面地址 |
base_commit.comments_url |
string |
是 |
否 |
提交评论的 API 地址 |
base_commit.commit |
object |
是 |
否 |
提交元信息 |
base_commit.author |
object |
是 |
否 |
提交作者 |
base_commit.committer |
object |
是 |
否 |
提交者 |
base_commit.parents |
object[] |
是 |
否 |
父提交列表 |
base_commit.commit 对象
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit.commit.author |
object |
是 |
否 |
提交作者信息 |
base_commit.commit.committer |
object |
是 |
否 |
提交者信息 |
base_commit.commit.tree |
object |
是 |
否 |
提交对应的树 |
base_commit.commit.message |
string |
是 |
否 |
提交信息 |
base_commit.commit.author 对象(base_commit.commit.committer 结构相同)
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit.commit.author.name |
string |
是 |
否 |
作者姓名 |
base_commit.commit.author.date |
string |
是 |
否 |
提交日期(ISO 8601 格式) |
base_commit.commit.author.email |
string |
是 |
否 |
作者邮箱 |
base_commit.commit.tree 对象
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit.commit.tree.sha |
string |
是 |
否 |
树的 SHA |
base_commit.commit.tree.url |
string |
是 |
否 |
树的 API 地址 |
base_commit.author 对象(base_commit.committer 结构相同)
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit.author.name |
string |
是 |
否 |
用户名 |
base_commit.author.id |
integer |
是 |
否 |
用户 ID |
base_commit.author.login |
string |
是 |
否 |
登录名 |
base_commit.author.type |
string |
是 |
否 |
用户类型,如 User |
base_commit.parents 数组元素
| 字段 |
类型 |
必返 |
可为空 |
说明 |
base_commit.parents.sha |
string |
是 |
否 |
父提交 SHA |
base_commit.parents.url |
string |
是 |
否 |
父提交的 API 地址 |
commits 数组元素
| 字段 |
类型 |
必返 |
可为空 |
说明 |
commits.sha |
string |
是 |
否 |
提交 SHA |
commits.commit |
object |
是 |
否 |
提交元信息 |
commits.author |
object |
是 |
否 |
提交作者 |
commits.committer |
object |
是 |
否 |
提交者 |
commits.commit 对象
| 字段 |
类型 |
必返 |
可为空 |
说明 |
commits.commit.author |
object |
是 |
否 |
提交作者信息 |
commits.commit.committer |
object |
是 |
否 |
提交者信息 |
commits.commit.message |
string |
是 |
否 |
提交信息 |
commits.commit.author 对象(commits.commit.committer 结构相同)
| 字段 |
类型 |
必返 |
可为空 |
说明 |
commits.commit.author.name |
string |
是 |
否 |
作者姓名 |
commits.commit.author.date |
string |
是 |
否 |
提交日期(ISO 8601 格式) |
commits.commit.author.email |
string |
是 |
否 |
作者邮箱 |
commits.author 对象(commits.committer 结构相同)
| 字段 |
类型 |
必返 |
可为空 |
说明 |
commits.author.name |
string |
是 |
否 |
用户名 |
commits.author.id |
integer |
是 |
否 |
用户 ID |
commits.author.login |
string |
是 |
否 |
登录名 |
files 数组元素
| 字段 |
类型 |
必返 |
可为空 |
说明 |
files.sha |
string |
是 |
否 |
文件 blob SHA |
files.filename |
string |
是 |
否 |
文件名 |
files.status |
string |
是 |
否 |
文件变更状态(如 added) |
files.additions |
integer |
是 |
否 |
新增行数 |
files.deletions |
integer |
是 |
否 |
删除行数 |
files.changes |
integer |
是 |
否 |
变更总行数 |
files.blob_url |
string |
是 |
否 |
文件 blob 地址 |
files.raw_url |
string |
是 |
否 |
原始文件地址 |
files.patch |
string |
是 |
否 |
文件变更补丁(diff) |
files.truncated |
integer |
是 |
否 |
补丁是否被截断(0/1) |
失败响应
接口可能返回非 200 状态码,调用方需据此处理错误。
400 参数错误
{
"error": "invalid_request",
"message": "参数 base 不能为空"
}
404 资源不存在
{
"error": "not_found",
"message": "仓库或提交不存在"
}
Note: 错误字段名以后端实际返回为准。
HTTP 响应状态码
| 状态码 |
说明 |
200 |
成功(OK) |
400 |
参数错误 |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
仓库或提交不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
请求示例
参数说明
示例未携带认证头(该接口允许匿名访问),如需认证也可自行携带 AtomGit 用户访问令牌。
<owner> 替换为仓库所属空间地址 path(企业、组织或个人的地址 path);
<repo> 替换为仓库路径 path;
<base> 替换为对比的起点(Commit SHA、分支名或标签名);
<head> 替换为对比的终点(Commit SHA、分支名或标签名)。
cURL
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/compare/<base>...<head>' \
-H 'Accept: application/json'
JavaScript
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/compare/<base>...<head>",
{
headers: {
"Accept": "application/json",
},
}
);
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python
import requests
resp = requests.get(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/compare/<base>...<head>",
headers={
"Accept": "application/json",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例
状态码: 200
{
"base_commit": {
"url": "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>",
"sha": "<sha>",
"html_url": "https://api.atomgit.com/<owner>/<repo>/commit/<sha>",
"comments_url": "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>/comments",
"commit": {
"author": {
"name": "octocat",
"date": "2024-08-13T11:34:35Z",
"email": "octocat@noreply.atomgit.com"
},
"committer": {
"name": "octocat",
"date": "2024-08-13T11:34:35Z",
"email": "octocat@noreply.atomgit.com"
},
"tree": {
"sha": "<tree-sha>",
"url": "https://api.atomgit.com/repos/<owner>/<repo>/git/trees/<tree-sha>"
},
"message": "new: 新增文件 test.py"
},
"author": {
"name": "octocat",
"id": 953,
"login": "octocat",
"type": "User"
},
"committer": {
"name": "octocat",
"id": 953,
"login": "octocat",
"type": "User"
},
"parents": [
{
"sha": "<parent-sha>",
"url": "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<parent-sha>"
}
]
},
"merge_base_commit": {
"url": "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>",
"sha": "<sha>",
"html_url": "https://api.atomgit.com/<owner>/<repo>/commit/<sha>",
"comments_url": "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>/comments",
"commit": {
"author": {
"name": "octocat",
"date": "2024-08-13T11:34:35Z",
"email": "octocat@noreply.atomgit.com"
},
"committer": {
"name": "octocat",
"date": "2024-08-13T11:34:35Z",
"email": "octocat@noreply.atomgit.com"
},
"tree": {
"sha": "<tree-sha>",
"url": "https://api.atomgit.com/repos/<owner>/<repo>/git/trees/<tree-sha>"
},
"message": "new: 新增文件 test.py"
},
"author": {
"name": "octocat",
"id": 953,
"login": "octocat",
"type": "User"
},
"committer": {
"name": "octocat",
"id": 953,
"login": "octocat",
"type": "User"
},
"parents": [
{
"sha": "<parent-sha>",
"url": "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<parent-sha>"
}
]
},
"commits": [
{
"sha": "<sha>",
"commit": {
"author": {
"name": "octocat",
"date": "2024-09-09T07:29:23Z",
"email": "octocat@noreply.atomgit.com"
},
"committer": {
"name": "octocat",
"date": "2024-09-09T07:29:23Z",
"email": "octocat@noreply.atomgit.com"
},
"message": "new: 新增文件 bbb.rs"
},
"author": {
"name": "octocat",
"id": 953,
"login": "octocat"
},
"committer": {
"name": "octocat",
"id": 953,
"login": "octocat"
}
}
],
"files": [
{
"sha": "<blob-sha>",
"filename": "bbb.rs",
"status": "added",
"additions": 3,
"deletions": 0,
"changes": 3,
"blob_url": "https://api.atomgit.com/<owner>/<repo>/blob/<blob-sha>/bbb.rs",
"raw_url": "https://api.atomgit.com/<owner>/<repo>/raw/<blob-sha>/bbb.rs",
"patch": "@@ -0,0 +1,3 @@\n+\n+\n+println!(\"hello\")",
"truncated": 0
}
],
"truncated": 0
}
错误码
| 错误码 |
说明 |
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
禁止访问 |
404 |
请求路径不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |