【问题标题】:git format-patch on empty commit returns unexpected result空提交上的 git format-patch 返回意外结果
【发布时间】:2016-01-08 16:49:40
【问题描述】:

在 git docs 上找不到关于这个问题的任何解释:

如果我创建一个虚拟提交,带有一些虚拟差异,我会得到一个正常的补丁 当我跑步时

git format-patch -1 -o outgoing/ -p -k

但如果最后一次提交是空提交,则由

生成

git commit --allow-empty "Some commit message"

那么格式补丁的输出将是一个空补丁。如果 第一种情况会产生这样的结果:

From 08cfdb2994554d834b89309ca96d9bf513e26a90 Mon Sep 17 00:00:00 2001
From: User <mail@example.com>
Date: Fri, 8 Jan 2016 12:44:57 +0000
Subject: dummy commit


diff --git a/lol.txt b/lol.txt
new file mode 100644
index 0000000..f944b38
--- /dev/null
+++ b/lol.txt
@@ -0,0 +1 @@
+:)
--
2.5.4 (Apple Git-61)

那么第二种情况不应该生成这样的东西吗?

From 2d486f25c48780e2e132047e681929fcccb7e60c Mon Sep 17 00:00:00 2001
From: User <mail@example.com>
Date: Fri Jan 8 12:43:55 2016 +0000
Subject: Some commit message


2.5.4 (Apple Git-61)

【问题讨论】:

    标签: git patch git-commit format-patch


    【解决方案1】:

    2022 年更新:使用 Git 2.35(2022 年第一季度),“git am(man) 学习 --empty=(stop|drop|keep)"--allow-empty 选项来调整对 e 的处理- 没有补丁的邮件。

    见“git-am with mailbox patch fails when it contains a cover letter”。


    2016:原始答案:

    注意:如果空提交不是最后一个,它会起作用(如“Git patch of empty commits”中所述)

    关于empty commit patch in this thread back in 2010的争论。

    一个好消息是format-patch 已经使用--always 命令行选项从空提交中生成消息,但是因为它不能与“am”一起应用,所以它是毫无意义的。

    --always 已通过to git diff-tree

    你需要做一些测试,但默认情况下,确实不包括空提交。

    【讨论】:

    • 实际上git am 可以应用具有正确差异部分的空补丁,这不会改变任何内容。作为一种解决方法,需要将此类差异附加到git format-patch --always 输出。
    • @IvanRomanov 好的。自从我在 2016 年初写答案以来,这可能已经改变了)
    【解决方案2】:

    从 git 邮件列表中提取:

    杰夫金说:

    I'm not sure if this is a bug or not.
    
    In the beginning, git's revision-traversal machinery generally does not show 
    commits which have no diff. Over the years, commands like "git log"
    learned to set the "always_show_header" option to show even empty commits. 
    But format-patch never did.
    

    然后 Junio C Hamano 补充道:

    The patch based workflow support is geared towards helping the recipient 
    of the patches a lot more than the contributors, and to prevent mistakes while 
    applying the patches, "am" would stop when it sees such an empty e-mail as you saw 
    (in the later part of message I am not quoting). After all, a "format-patch" output 
    that does not have any patch would be indistinguishable from discussion e-mail 
    messages and the recipient would not want to end up with no-op commits 
    that record such messages.
    
    So I think skipping no-op commit from the output was done pretty much deliberately 
    and it is definitely not a bug.  I however do not think it is incorrect 
    to say that it is a lack of feature that nobody 
    so far found necessary or beneficial.
    
    I would not refuse to consider adding a new option to "format-patch" 
    to emit such a no-op message, and add a "having no patch is OK, just record a 
    no-op commit" option to "am", though.  But I do not see a clear benefit from 
    such change--it sounds more like a set of"because we could" not 
    "because we need to" changes to me.
    

    线程在http://git.661346.n2.nabble.com/git-format-patch-on-empty-commit-td7645342.html 感谢@VonC 找到它

    【讨论】:

    • 有趣。有链接吗?
    • @VonC 不,它来自邮件列表.. 我不知道他们是否有某种公共档案..
    • 这个答案是昨晚 11 小时前 9 点在里斯本发布的
    猜你喜欢
    • 2011-12-11
    • 2018-07-02
    • 2012-06-27
    • 2023-02-05
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多