我发布了这个问题后,这是针对git源代码中builtin/log.c的补丁,给了我想要的确切行为。
我想要的行为如下:
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”命令中,数据就在那里。 :-)
git log --left-right --cherry-mark A...B
中实现类似的功能。在git cherry
中,有一个更清晰的显示位置,比在git log --left-right
中更好。 - torek