首页 > 解决方案 > 单个缺失提交的 git-cherry 等效项是什么?

问题描述

如何检查单个提交是否已应用于特定分支?

以文档git-cherry为例:

       $ git log --graph --oneline --decorate --boundary origin/master...topic
       * 7654321 (origin/master) upstream tip commit
       [... snip some other commits ...]
       * cccc111 cherry-pick of C
       * aaaa111 cherry-pick of A
       [... snip a lot more that has happened ...]
       | * cccc000 (topic) commit C
       | * bbbb000 commit B
       | * aaaa000 commit A
       |/
       o 1234567 branch point

       $ git cherry origin/master topic
       - cccc000... commit C
       + bbbb000... commit B
       - aaaa000... commit A

我怎么知道它具有与无需处理整个树cccc000相同的内容?- cccc111这可能吗?

请注意,它git-cherry依赖于补丁内容(差异),这是问题的关键。

标签: gitpatchgit-cherry

解决方案


git log有一个--cherry-mark选项可以添加关于对称差异的信息(又名“3-dots operator” A...B

尝试运行:

git log --oneline --graph --boundary --cherry-mark master...topic

您应该看到具有前缀+(或*--graph选项打开时)的唯一提交,并且两边都有的提交=


如果您想知道提交是如何匹配的:git patch-id计算cherry-pick / rebase 使用的结果。

git patch-id期望在 STDIN 上有一个补丁(由git showor产生):git diff

$ git show <commit-ish> | git patch-id
<hash for patch> <hash of input revision, if it can determine a revision>

例如:您可以在以下位置查看patch-id所有单个提交的 s A...B

git rev-list origin/master...forkpoint | while read sha1; do
    git show $sha1 | git patch-id
done

您可以在脚本中使用此结果,以更明确地打印提交的链接方式。


推荐阅读