【问题标题】:What is the git-cherry equivalent for a single missing commit?单个缺失提交的 git-cherry 等效项是什么?
【发布时间】:2020-10-13 12:13:24
【问题描述】:

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

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 依赖于补丁内容(差异),这是问题的关键。

【问题讨论】:

    标签: git patch git-cherry


    【解决方案1】:

    git log 有一个 --cherry-mark 选项,用于添加有关对称差异的信息(也称为“三点运算符”A...B

    尝试运行:

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

    您应该会看到以+ 为前缀的唯一提交(或*,当--graph 选项打开时),并且两侧都有以= 为前缀的提交。


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

    git patch-id 需要一个补丁(由 git showgit diff 生成)在 STDIN 上:

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

    例如:您可以在A...B 中查看所有单个提交的patch-ids:

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

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

    【讨论】:

    • LeGEC 感谢您的回答!它几乎就在现场。然而,这看起来我们仍然必须完全比较两个分支,这在我的情况下是一个问题(例如,内核有一个遥远的合并基础,有数千个提交相互测试)。你认为可以通过一次提交来做到这一点吗?如果没有,我会按原样接受这个答案。
    • 我想我误解了你最初的问题:你想两个两个匹配标有= 的提交吗?我更新了我的答案。
    猜你喜欢
    • 2013-03-26
    • 2018-01-05
    • 2016-10-24
    • 2021-01-18
    • 2012-11-05
    • 2017-01-30
    • 2023-02-02
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多