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

[PATCH] commit: add -f to force creation when no changes or an empty message

From
Ivan Ukhov <ivan.ukhov@gmail.com>
Date
Mar 29, 2015, 15:34 UTC
Message-ID
<E2201BDB-4441-4BD0-B0ED-2F39A2838A7F@gmail.com>

An attempt to commit gets rejected if there are no changes staged or there is no message given. In such a case, the --allow-empty and --allow-empty-message flags can be used to force the action. The standard approach to force an action, however, is the -f/--force flag, as used in other built-ins.

Signed-off-by: Ivan Ukhov <ivan.ukhov@gmail.com>
---
 builtin/commit.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index da79ac4..fb76aee 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -113,7 +113,7 @@ static char *fixup_message, *squash_message;
 static int all, also, interactive, patch_interactive, only, amend, signoff;
 static int edit_flag = -1; /* unspecified */
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
-static int no_post_rewrite, allow_empty_message;
+static int no_post_rewrite, allow_empty_message, force;
 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
 static char *sign_commit;

@@ -1614,6 +1614,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "amend", &amend, N_("amend previous commit")),
 		OPT_BOOL(0, "no-post-rewrite", &no_post_rewrite, N_("bypass post-rewrite hook")),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
+		OPT__FORCE(&force, N_("force creation when no changes or an empty message")),
 		/* end commit contents options */

 		OPT_HIDDEN_BOOL(0, "allow-empty", &allow_empty,
@@ -1653,6 +1654,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	argc = parse_and_validate_options(argc, argv, builtin_commit_options,
 					  builtin_commit_usage,
 					  prefix, current_head, &s);
+
+	allow_empty += force;
+	allow_empty_message += force;
+
 	if (dry_run)
 		return dry_run_commit(argc, argv, prefix, current_head, &s);
 	index_file = prepare_index(argc, argv, prefix, current_head, 0);
--
2.3.4
Message 1 of 1 in “commit: add -f to force creation when no changes or an empty message”
  1. commit: add -f to force creation when no changes or an empty messageIvan Ukhov, Mar 29, 2015

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.