这是一个避免列出远程或使用 gerrit REST API 的解决方案。
gerrit 的每一个变化都有一个特殊的引用,称为meta
:
git fetch origin refs/changes/98/898/meta
获取后,它会指向一个提交链,这些提交链代表此更改的更新历史记录。除其他外,提交消息有一个预告片Patch-set
,其中将包含此更改适用的补丁集编号:
> git log FETCH_HEAD
Author: Gerrit User 1000026 <1000026@dc17d2f6-4abc-4304-ba32-8b7ca44eda6b>
Date: Wed Aug 19 06:36:23 2020 +0100
Update patch set 6
Change has been successfully cherry-picked as 68e4bc1612d61110ccfae4ac94bbd4458b2868a9 by Leonid Usov
Patch-set: 6
Subject: Add a new feature
Status: merged
Commit: 68e4bc1612d61110ccfae4ac94bbd4458b2868a9
Tag: autogenerated:gerrit:merged
Groups: bd9a33f7432c39308935056720de59168ff04003
Label: Code-Review=+2
Label: Verified=+1 Gerrit User 1000001 <1000001@dc17d2f6-4abc-4304-ba32-8b7ca44eda6b>
Label: SUBM=+1
Submission-id: 914
Submitted-with: OK
Submitted-with: OK: Code-Review: Gerrit User 1000026 <1000026@dc17d2f6-4abc-4304-ba32-8b7ca44eda6b>
Submitted-with: OK: Verified: Gerrit User 1000001 <1000001@dc17d2f6-4abc-4304-ba32-8b7ca44eda6b>
自然,该分支的尖端将指向最新更新,因此将包含最新补丁集的编号。以下是我如何知道更改的最新补丁集编号的方法:
» git fetch origin refs/changes/14/914/meta \
&& git cat-file -p FETCH_HEAD \
| git interpret-trailers --parse \
| sed -E "/^Patch-set:/s/([[:alpha:]-]+):[[:space:]]*(.*)/\2/;q"
From ssh://gerrit/repo
* branch refs/changes/14/914/meta -> FETCH_HEAD
6
随意6
在标准输出上使用它;)