Does Git really need a commit message to go with a commit?

5 messages, 3 authors, 2016-06-15 · open the first message on its own page

Does Git really need a commit message to go with a commit?

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:48:33

git-commit(1) doesn't allow you to make a commit without a commit
message. This is annoying and doesn't properly preserve history in
applications like snerp-vortex which replay a SVN dump into Git. You
have to add `$msg = "Git made me do it" unless length $msg' somewhere.

Is there really no way to add a commit with no message with the git
tools? Will anything break if I manually construct a commit with no
message? Are commit messages inherently part of the format or does
git-commit(1) just think it knows better than me?

Re: Does Git really need a commit message to go with a commit?

From: Avery Pennarun <hidden>
Date: 2016-06-15 22:48:33

On Sat, Apr 3, 2010 at 6:06 PM, Ævar Arnfjörð Bjarmason
[off-list ref] wrote:
git-commit(1) doesn't allow you to make a commit without a commit
message. This is annoying and doesn't properly preserve history in
applications like snerp-vortex which replay a SVN dump into Git. You
have to add `$msg = "Git made me do it" unless length $msg' somewhere.

Is there really no way to add a commit with no message with the git
tools? Will anything break if I manually construct a commit with no
message? Are commit messages inherently part of the format or does
git-commit(1) just think it knows better than me?
git-commit isn't really meant to be used by scripts.  Try using
git-commit-tree instead, which doesn't enforce a commit message.

(Or use git fast-import; a quick glance at Snerp suggests that it's
intended to be *fast*; using fast-import ought to make things vastly
quicker.)

Avery

[PATCH] Add option to git-commit to allow empty log messages

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:48:33

Change git-commit(1) to accept a --allow-empty-message option
analogous to the existing --allow-empty option which allows empty
trees. This is mainly for compatability with foreign SCM systems.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Documentation/git-commit.txt          |   12 +++++++--
 builtin/commit.c                      |    7 +++--
 t/t7510-commit-allow-empty-message.sh |   41 +++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)
 create mode 100755 t/t7510-commit-allow-empty-message.sh
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 64fb458..2c1c2e1 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -10,9 +10,9 @@ SYNOPSIS
 [verse]
 'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
 	   [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
-	   [--allow-empty] [--no-verify] [-e] [--author=<author>]
-	   [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
-	   [[-i | -o ]<file>...]
+	   [--allow-empty] [--allow-empty-message] [--no-verify] [-e]
+	   [--author=<author>] [--date=<date>] [--cleanup=<mode>]
+	   [--status | --no-status] [--] [[-i | -o ]<file>...]
 
 DESCRIPTION
 -----------
@@ -131,6 +131,12 @@ OPTIONS
 	from making such a commit.  This option bypasses the safety, and
 	is primarily for use by foreign scm interface scripts.
 
+--allow-empty-message::
+	Like --allow-empty this command is primarily for use by foreign
+	scm interface scripts. It allows you to create a commit with an
+	empty commit message without using plumbing commands like
+	linkgit:git-commit-tree[1].
+
 --cleanup=<mode>::
 	This option sets how the commit message is cleaned up.
 	The  '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
diff --git a/builtin/commit.c b/builtin/commit.c
index c5ab683..7fd963e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -65,8 +65,8 @@ static const char *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
-static int no_post_rewrite;
+static int quiet, verbose, no_verify, allow_empty, allow_empty_message, dry_run;
+static int no_post_rewrite, renew_authorship;
 static char *untracked_files_arg, *force_date;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -141,6 +141,7 @@ static struct option builtin_commit_options[] = {
 	OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
 	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 	OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
+	OPT_BOOLEAN(0, "allow-empty-message", &allow_empty_message, "ok to record a change with an empty message"),
 	/* end commit contents options */
 
 	OPT_END()
@@ -1293,7 +1294,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
 	if (cleanup_mode != CLEANUP_NONE)
 		stripspace(&sb, cleanup_mode == CLEANUP_ALL);
-	if (message_is_empty(&sb)) {
+	if (message_is_empty(&sb) && !allow_empty_message) {
 		rollback_index_files();
 		fprintf(stderr, "Aborting commit due to empty commit message.\n");
 		exit(1);
diff --git a/t/t7510-commit-allow-empty-message.sh b/t/t7510-commit-allow-empty-message.sh
new file mode 100755
index 0000000..d7dc0da
--- /dev/null
+++ b/t/t7510-commit-allow-empty-message.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
+#
+
+test_description='git commit --allow-empty-message'
+
+. ./test-lib.sh
+
+commit_msg_is () {
+	test "`git log --pretty=format:%s%b -1`" = "$1"
+}
+
+# A sanity check to see if commit is working at all.
+test_expect_success 'a basic commit in an empty tree should succeed' '
+	(
+		echo content > foo &&
+		git add foo &&
+		git commit -m "initial commit"
+	) &&
+	commit_msg_is "initial commit"
+'
+
+test_expect_success 'Commit no message with --allow-empty-message' '
+	(
+		echo "more content" >> foo &&
+		git add foo &&
+		printf "" | git commit --allow-empty-message
+	) &&
+	commit_msg_is ""
+'
+
+test_expect_success 'Commit a message with --allow-empty-message' '
+	(
+		echo "even more content" >> foo &&
+		git add foo &&
+		git commit --allow-empty-message -m"hello there"
+	) &&
+	commit_msg_is "hello there"
+'
+test_done
-- 
1.7.0.4.298.gc81d

Re: [PATCH] Add option to git-commit to allow empty log messages

From: David Aguilar <hidden>
Date: 2016-06-15 22:48:33

On Sun, Apr 04, 2010 at 02:49:16PM +0000, Ævar Arnfjörð Bjarmason wrote:
Change git-commit(1) to accept a --allow-empty-message option
analogous to the existing --allow-empty option which allows empty
trees. This is mainly for compatability with foreign SCM systems.
It's hard enough to get co-workers to write good commit
messages.  I wouldn't want to encourage them to skip writing
them altogether (by the existence of this feature).

Is there any reason why the git commit-tree plumbing didn't
suffice?

(in other words, "sure we can", but I'm asking,
 "are you sure we should?")

Just my $.02.
Hey, we just had a small earthquake.  Fun =)

quoted hunk
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Documentation/git-commit.txt          |   12 +++++++--
 builtin/commit.c                      |    7 +++--
 t/t7510-commit-allow-empty-message.sh |   41 +++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)
 create mode 100755 t/t7510-commit-allow-empty-message.sh
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 64fb458..2c1c2e1 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -10,9 +10,9 @@ SYNOPSIS
 [verse]
 'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
 	   [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
-	   [--allow-empty] [--no-verify] [-e] [--author=<author>]
-	   [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
-	   [[-i | -o ]<file>...]
+	   [--allow-empty] [--allow-empty-message] [--no-verify] [-e]
+	   [--author=<author>] [--date=<date>] [--cleanup=<mode>]
+	   [--status | --no-status] [--] [[-i | -o ]<file>...]
 
 DESCRIPTION
 -----------
@@ -131,6 +131,12 @@ OPTIONS
 	from making such a commit.  This option bypasses the safety, and
 	is primarily for use by foreign scm interface scripts.
 
+--allow-empty-message::
+	Like --allow-empty this command is primarily for use by foreign
+	scm interface scripts. It allows you to create a commit with an
+	empty commit message without using plumbing commands like
+	linkgit:git-commit-tree[1].
+
 --cleanup=<mode>::
 	This option sets how the commit message is cleaned up.
 	The  '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
diff --git a/builtin/commit.c b/builtin/commit.c
index c5ab683..7fd963e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -65,8 +65,8 @@ static const char *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
-static int no_post_rewrite;
+static int quiet, verbose, no_verify, allow_empty, allow_empty_message, dry_run;
+static int no_post_rewrite, renew_authorship;
 static char *untracked_files_arg, *force_date;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -141,6 +141,7 @@ static struct option builtin_commit_options[] = {
 	OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
 	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 	OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
+	OPT_BOOLEAN(0, "allow-empty-message", &allow_empty_message, "ok to record a change with an empty message"),
 	/* end commit contents options */
 
 	OPT_END()
@@ -1293,7 +1294,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
 	if (cleanup_mode != CLEANUP_NONE)
 		stripspace(&sb, cleanup_mode == CLEANUP_ALL);
-	if (message_is_empty(&sb)) {
+	if (message_is_empty(&sb) && !allow_empty_message) {
 		rollback_index_files();
 		fprintf(stderr, "Aborting commit due to empty commit message.\n");
 		exit(1);
diff --git a/t/t7510-commit-allow-empty-message.sh b/t/t7510-commit-allow-empty-message.sh
new file mode 100755
index 0000000..d7dc0da
--- /dev/null
+++ b/t/t7510-commit-allow-empty-message.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
+#
+
+test_description='git commit --allow-empty-message'
+
+. ./test-lib.sh
+
+commit_msg_is () {
+	test "`git log --pretty=format:%s%b -1`" = "$1"
+}
+
+# A sanity check to see if commit is working at all.
+test_expect_success 'a basic commit in an empty tree should succeed' '
+	(
+		echo content > foo &&
+		git add foo &&
+		git commit -m "initial commit"
+	) &&
+	commit_msg_is "initial commit"
+'
+
+test_expect_success 'Commit no message with --allow-empty-message' '
+	(
+		echo "more content" >> foo &&
+		git add foo &&
+		printf "" | git commit --allow-empty-message
+	) &&
+	commit_msg_is ""
+'
+
+test_expect_success 'Commit a message with --allow-empty-message' '
+	(
+		echo "even more content" >> foo &&
+		git add foo &&
+		git commit --allow-empty-message -m"hello there"
+	) &&
+	commit_msg_is "hello there"
+'
+test_done
-- 
1.7.0.4.298.gc81d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
		David

Re: [PATCH] Add option to git-commit to allow empty log messages

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:48:33

In retrospect I probably should have sent a [PATCH RFC], this is
obviously somewhat of a delicate subject.

On Sun, Apr 4, 2010 at 21:21, Shawn Pearce [off-list ref] wrote:
Isn't this exactly why git-commit-tree exists?  I don't really see a reason
to support scripting the porcelain git commit.
It's not so much about supporting scripting as exporting the
capabilities of the porcelain to the frontend utilities without
artificial limitations.

On Sun, Apr 4, 2010 at 22:43, David Aguilar [off-list ref] wrote:
On Sun, Apr 04, 2010 at 02:49:16PM +0000, Ævar Arnfjörð Bjarmason wrote:
quoted
Change git-commit(1) to accept a --allow-empty-message option
analogous to the existing --allow-empty option which allows empty
trees. This is mainly for compatability with foreign SCM systems.
Is there any reason why the git commit-tree plumbing didn't
suffice?
I encountered this limitation most recently while using hacking
snerp-vortex which uses git-commit(1) directly. While it should
ideally use git-commit-tree(1) or git-fast-import(1) it was easier at
the time to do:

    message ||= "Git made me";

I thought it was silly that I had to either do that to fix an
otherwise working piece of software or rewrite how it does commits,
hence the patch.
It's hard enough to get co-workers to write good commit
messages.  I wouldn't want to encourage them to skip writing
them altogether (by the existence of this feature).
I'm a big fan of good commit messages, that's another reason why I
think this feature is a good idea.

I've read too many commit messages from people who're obviously
determined not to write any, but are being forced to do so by their
tools. Favorites include "more updates", "some changes", "..." (the
list goes on). I'd rather get nothing at all from those people than
more meaningless drivel. It would increase the signal-to-noise ratio
of git-log(1) output.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help