2016-01-08 92 views
1

找不到對這個問題上git的文檔任何解釋:git的格式補丁

如果我創建一個虛擬的承諾,有一些虛擬的差異,我得到一個正常的補丁 當我運行

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 <[email protected]> 
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 <[email protected]> 
Date: Fri Jan 8 12:43:55 2016 +0000 
Subject: Some commit message 


2.5.4 (Apple Git-61) 

回答

1

從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Ç濱野又說:可用

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找到它

+0

有趣。你有鏈接嗎? – VonC

+0

@VonC不,它來自郵件列表..我不知道他們是否有某種公共檔案.. – pedrorijo91

+0

好吧,你有一個該線程的日期? – VonC

1

注:如果空承諾是不是最後一次,它會工作

有一個辯論關於empty commit patch in this thread back in 2010(如「Git patch of empty commits」提到)。

一個半好消息是,format-patch已經採取--always命令行選項來生成一個消息出來一個空的承諾,而是因爲它不能與「am」適用,這是毫無意義。

--always傳遞to git diff-tree

你需要做一些測試,但默認情況下,確實不包括空的提交。