git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Cherry-picking commits with empty messages

From
Chris Webb <chris@arachsys.com>
Date
Aug 1, 2012, 11:16 UTC
Message-ID
<20120801111658.GA21272@arachsys.com>

Whilst doing some extra sanity checking of my git-rebase--interactive.sh patch yesterday, I came across a behaviour which has been present for some time, but seems surprising. You can reproduce with

  $ git init -q foo && cd foo
  $ touch one && git add one && git commit -q -m one
  $ touch two && git add two && git commit -q -m two
  $ touch three && git add three && git commit -q -m '' --allow-empty-message
  $ touch four && git add four && git commit -q -m '' --allow-empty-message
  $ git rebase -i HEAD~3 # and swap the two commits with empty messages
  Aborting commit due to empty commit message.
  Could not apply 59a8fde... 

This happens on my ancient laptop which is apparently running 1.7.8.3, as well as current master, so is unconnected to recent changes.

The reason is that git cherry-pick won't pick a commit with an empty commit message, even when that message is unmodified from the original:

  $ git rebase --abort
  $ git checkout -q HEAD~2
  $ git cherry-pick 59a8fde
  Aborting commit due to empty commit message.

I can see that this check could make sense when the message has been modified, but it seems strange when it hasn't, and isn't ideal behaviour when called from rebase -i. (We otherwise make sure we call git commit with --allow-empty-message to avoid problems with reordering or editing empty commits.)

I could just remove the check in the 'message unmodified' case with something like

diff --git a/sequencer.c b/sequencer.c
index bf078f2..cf8bc05 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -306,6 +306,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
 	if (!opts->edit) {
 		argv_array_push(&array, "-F");
 		argv_array_push(&array, defmsg);
+		argv_array_push(&array, "--allow-empty-message");
 	}
 
 	if (allow_empty)

but perhaps there are other users of the sequencer for whom this check is
desirable? If so, would an --allow-empty-message to git cherry-pick be a
better plan, which git rebase -i can use where appropriate?

Best wishes,

Chris.
Next: Junio C Hamano
Message 1 of 11 in “Cherry-picking commits with empty messages”
  1. Chris WebbAug 1, 2012
  2. Junio C HamanoAug 1, 2012
  3. Angus HammondAug 1, 2012
  4. Junio C HamanoAug 1, 2012
  5. Angus HammondAug 2, 2012
  6. Chris WebbAug 2, 2012
  7. cherry-pick: add --allow-empty-message optionChris Webb, Aug 2, 2012
  8. Neil HormanAug 6, 2012
  9. Chris WebbAug 6, 2012
  10. Neil HormanAug 6, 2012
  11. Neil HormanAug 3, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.