Commits对比
GET /api/v5/repos/{owner}/{repo}/compare/{base}...{head}
该接口用于查询指定仓库中两个提交之间的对比结果,支持以 Commit SHA、分支名或标签名作为对比起点与终点,返回对比范围内的提交列表、变更文件及增删行数等详细信息。
访问令牌支持说明
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问
此接口允许匿名访问
请求参数
响应参数
base_commit 对象(merge_base_commit 结构与之相同)
base_commit.commit 对象
base_commit.commit.author 对象(base_commit.commit.committer 结构相同)
base_commit.commit.tree 对象
base_commit.author 对象(base_commit.committer 结构相同)
base_commit.parents 数组元素
commits 数组元素
commits.commit 对象
commits.commit.author 对象(commits.commit.committer 结构相同)
commits.author 对象(commits.committer 结构相同)
files 数组元素
失败响应
接口可能返回非 200 状态码,调用方需据此处理错误。
400 参数错误
{
"error": "invalid_request",
"message": "参数 base 不能为空"
}
404 资源不存在
{
"error": "not_found",
"message": "仓库或提交不存在"
}
Note: 错误字段名以后端实际返回为准。
HTTP 响应状态码
请求示例
参数说明
示例未携带认证头(该接口允许匿名访问),如需认证也可自行携带 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
}
错误码