一个快速的附录(我发布了这个问题)——这个针对 builtin/log.c 的补丁(来自 git 的源代码)给了我我想要的确切行为。
这是我想要的行为:
git cherry -v test HEAD
+ 8cc1e2105f387eeede67a87688b6bfae0cab42c6 - m
- 8ce948ca1b54d551581f4574bda2c215cc96a351 1c156417bff133e25664fe7047b5df6a81fbd2f7 a
- 1e73b75de891eab9314856558624e9b4c21bbb1f f207a10a5249f9e0fe74184f8b03c75bbf7488c5 b
- 04876f4e615b2bb70b969e99de15ec78b1ea84f6 4b8bc3eab7c625f298ca3bd031ba141b66240da4 c
这是补丁:
diff --git a/builtin/log.c b/builtin/log.c
index d104d5c688..a32f0bede7 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -2153,17 +2153,19 @@ static const char * const cherry_usage[] = {
NULL
};
-static void print_commit(char sign, struct commit *commit, int verbose,
+static void print_commit(char sign, struct commit *commit, struct commit *other, int verbose,
int abbrev, FILE *file)
{
if (!verbose) {
- fprintf(file, "%c %s\n", sign,
- find_unique_abbrev(&commit->object.oid, abbrev));
+ fprintf(file, "%c %s %s\n", sign,
+ find_unique_abbrev(&commit->object.oid, abbrev),
+ other ? find_unique_abbrev(&other->object.oid, abbrev) : "-");
} else {
struct strbuf buf = STRBUF_INIT;
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
- fprintf(file, "%c %s %s\n", sign,
+ fprintf(file, "%c %s %s %s\n", sign,
find_unique_abbrev(&commit->object.oid, abbrev),
+ other ? find_unique_abbrev(&other->object.oid, abbrev) : "-",
buf.buf);
strbuf_release(&buf);
}
@@ -2238,12 +2240,17 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
}
while (list) {
+ struct patch_id *id;
+ struct commit *upstream_commit = NULL;
char sign = '+';
commit = list->item;
- if (has_commit_patch_id(commit, &ids))
+ id = has_commit_patch_id(commit, &ids);
+ if (id) {
sign = '-';
- print_commit(sign, commit, verbose, abbrev, revs.diffopt.file);
+ upstream_commit = id->commit;
+ }
+ print_commit(sign, commit, upstream_commit, verbose, abbrev, revs.diffopt.file);
list = list->next;
}
如果有某种方法可以在不尝试将补丁接受到 git 项目中的情况下完成此操作,显然会更好,但认为发布此内容可能有助于明确我在寻找什么。果然,数据就在“git cherry”命令的底层。:-)