Reputation: 7845
Couldn't find any explanation on git docs on this issue:
If I create a dummy commit, with some dummy diff, I get a normal patch when I run
git format-patch -1 -o outgoing/ -p -k
but if the last commit is an empty commit, generated by
git commit --allow-empty "Some commit message"
then the output of the format patch will be an empty patch. If the first case produces something like this:
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)
then the second case shouldn't generate something like this instead ?
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)
Upvotes: 2
Views: 1183
Reputation: 1323115
Update 2022: With Git 2.35 (Q1 2022), "git am
"(man) learns --empty=(stop|drop|keep)"
and --allow-empty
options to tweak what is done to a piece of e-mail without a patch in it.
See "git-am with mailbox patch fails when it contains a cover letter".
2016: original answer:
Note: if the empty commit was not the last, it would work (as mentioned in "Git patch of empty commits")
There was a debate about empty commit patch in this thread back in 2010.
A half-good news is that
format-patch
already takes--always
command line option to generate a message out of an empty commit, but because it cannot be applied with "am
", it is rather pointless.
(--always
is passed to git diff-tree
)
You need to do some test, but by default, empty commits are indeed not included.
With Git 2.41 (Q2 2023), "git format-patch
"(man) learned to write a log-message only output file for empty commits.
See commit 94c4289 (03 Mar 2023) by John Keeping (johnkeeping
).
(Merged by Junio C Hamano -- gitster
-- in commit 5c92a45, 19 Mar 2023)
format-patch
: output header for empty commitsSigned-off-by: John Keeping
When formatting an empty commit, it is surprising that a totally empty file is generated.
Set the flag to always print the header, matching the behaviour ofgit log
.
Upvotes: 3
Reputation: 7845
Extracted from git mailing list:
Jeff King said:
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.
And then Junio C Hamano added:
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.
thread available at http://git.661346.n2.nabble.com/git-format-patch-on-empty-commit-td7645342.html thanks to @VonC for finding it
Upvotes: 1