Thread View: linux.kernel.git
15 messages
15 total messages
Started by Erik Cervin-Edin
Tue, 24 Nov 2026 23:32
[PATCH v4 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Author: Erik Cervin-Edin
Date: Tue, 24 Nov 2026 23:32
Date: Tue, 24 Nov 2026 23:32
350 lines
27095 bytes
27095 bytes
Changes since v3:
* New 1/3 refactors prepare_to_commit() to write the --fixup subject
in a block before the message-source chain, as --squash already
does. On v3 1/2 Phillip found it unfortunate that the -m and -F
arms had to be guarded with "!fixup_message" while the fixup arm
duplicated their work [1] and I agree.
Originally, I wanted to avoid a refactor -- but the guards were
getting nasty, and a refactor is the proper fix. It turned out not
to be that difficult and I think it makes the series land cleaner.
With the subject written up front, the -m and -F arms serve every
--fixup variant unchanged, and the fixup arm is left with only the
amend case.
* 2/3 and 3/3 are rebuilt on top of 1/3, which now carries most of
the change to builtin/commit.c.
* 3/3 tests: took Phillip's suggestions [2].
* Log messages: reworded 2/3's history of why these options were
rejected; 3/3 now gives its motivation, with a use case, and
explains the "amend!" handling that the v3 cover letter described.
Background
----------
Today only -m works with plain --fixup, and neither -m nor -F works
with --fixup=amend: or --fixup=reword:, which makes those modes
awkward to drive non-interactively. 2/3 lets -m and -F supply the
message for all --fixup variants. 3/3 does the same for -c/-C, so
that all four message sources behave consistently across the plain,
amend, and reword forms.
As in v3, -c/-C go through prepare_amend_commit(), so if the source
commit is itself an "amend!" commit, its subject line is dropped and
only the body is copied. This is what a no-source
--fixup=amend:<commit> already does. The helper only knows about
"amend!" and not "fixup!" or "squash!"; that is pre-existing and I
have left it alone here.
The earlier rounds are described in the v2 [3] and v3 [4] cover
letters.
[1] https://lore.kernel.org/git/3354eeb4-3b9d-474e-bf9f-8efd2ca3a512@gmail.com/
[2] https://lore.kernel.org/git/de12af28-a64e-4472-8bd4-b65200772dbe@gmail.com/
[3] https://lore.kernel.org/git/cover.1779792311.git.erik@cervined.in/
[4] https://lore.kernel.org/git/cover.1790082176.git.erik@cervined.in/
Erik Cervin-Edin (3):
commit: write the --fixup subject the way --squash does
commit: allow -m/-F for all --fixup variants
commit: allow -c/-C for all --fixup variants
Documentation/git-commit.adoc | 22 +++--
builtin/commit.c | 61 ++++++------
t/t7500-commit-template-squash-signoff.sh | 114 +++++++++++++++++++---
3 files changed, 138 insertions(+), 59 deletions(-)
Range-diff against v3:
-: ---------- > 1: ebae1fbe05 commit: write the --fixup subject the way --squash does
1: 4a493867bb ! 2: 051b659965 commit: allow -m/-F for all kinds of --fixup
@@ Metadata
Author: Erik Cervin-Edin <erik@cervined.in>
## Commit message ##
- commit: allow -m/-F for all kinds of --fixup
+ commit: allow -m/-F for all --fixup variants
The ability to provide a commit message for git commit --fixup and its
- variations is limited:
+ variants is limited:
- * Plain --fixup only allows using the -m flag
+ * Plain --fixup accepts -m but not -F
- * The amend/reword --fixup variants only allow supplying the message
- using an editor
+ * The amend/reword variants accept a message only through an editor
+ (or a GIT_EDITOR script standing in for one)
- For amend/reword, the -m and -F flags are rejected: -m is caught by a
- die() in prepare_to_commit(), and -F is caught by
- die_for_incompatible_opt4() which groups -F with --fixup as mutually
- exclusive. This makes these modes poorly suited for non-interactive
+ This makes the amend/reword variants poorly suited for non-interactive
workflows -- notably when using AI coding agents.
- When support to use the -m option was introduced in [1] it was noted
- that there could be support for other options but at the time the use
- case was deemed too niche. Later, when the amend suboption was
- introduced in [2] -m support for amend fixups was discussed but not
- pursued, and -F was already caught by the higher-layer incompatibility
- check grouping it with --fixup.
+ When --fixup learned to take -m [1], it was noted that other options
+ (-c/-C/-F) could also be supported, but were left out for lack of a
+ clear use case. Later, when the amend suboption was introduced in [2],
+ -m was initially supported for amend fixups too, but was dropped for the
+ same reason [3].
- The rejections of these options hark back to when --fixup was
- introduced in [3] and as noted in [1] -- there's nothing inherently
- preventing support for them. The current patchwork of which flags
- work with which --fixup variants has no strong logic to it, and
- allowing all of them simplifies both the code and the interface.
+ The rejections of these options hark back to when --fixup was introduced
+ in [4], but as [1] noted, nothing inherently prevents supporting them.
- Allow -m and -F to supply the message body for all --fixup variations,
- mirroring the flow of a regular commit. -c and -C, which are blocked
- by the same incompatibility check, are handled in the next commit.
+ The current patchwork of which options work with which --fixup variants
+ has no strong logic to it, and allowing all of them simplifies the
+ interface.
+
+ Allow -m and -F to supply the message body for all --fixup variants,
+ mirroring the flow of a regular commit. With --fixup=amend/reword the
+ given message replaces the one that would otherwise be copied from the
+ target commit. Options -c and -C are handled in the next commit.
1. 30884c9afc (commit: add support for --fixup <commit> -m"<extra
message>", 2017-12-22)
@@ Commit message
2. 494d314a05 (commit: add amend suboption to --fixup to create amend!
commit, 2021-03-15)
- 3. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
+ 3. https://lore.kernel.org/git/xmqqft1o80pe.fsf@gitster.g/
+
+ 4. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
2010-11-02)
Helped-by: Junio C Hamano <gitster@pobox.com>
- Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
+ Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
## Documentation/git-commit.adoc ##
@@ Documentation/git-commit.adoc: include::diff-context-options.adoc[]
## builtin/commit.c ##
@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
- if (have_option_m && !fixup_message) {
- strbuf_addbuf(&sb, &message);
- hook_arg1 = "message";
-- } else if (logfile && !strcmp(logfile, "-")) {
-+ } else if (logfile && !fixup_message && !strcmp(logfile, "-")) {
- if (isatty(0))
- fprintf(stderr, _("(reading log message from standard input)\n"));
- if (strbuf_read(&sb, 0, 0) < 0)
- die_errno(_("could not read log from standard input"));
- hook_arg1 = "message";
-- } else if (logfile) {
-+ } else if (logfile && !fixup_message) {
- if (strbuf_read_file(&sb, logfile, 0) < 0)
- die_errno(_("could not read log file '%s'"),
- logfile);
- hook_arg1 = "message";
-- } else if (use_message) {
-+ } else if (use_message && !fixup_message) {
- const char *buffer;
- buffer = strstr(use_message_buffer, "\n\n");
- if (buffer)
-@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
- hook_arg1 = "message";
-
+ repo_format_commit_message(the_repository, c, fmt, &sb,
+ &ctx);
+ free(fmt);
+- if (have_option_m && !strcmp(fixup_prefix, "amend"))
+- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
+ } else if (squash_message) {
/*
-- * Only `-m` commit message option is checked here, as
-- * it supports `--fixup` to append the commit message.
-- *
-- * The other commit message options `-c`/`-C`/`-F` are
-- * incompatible with all the forms of `--fixup` and
-- * have already errored out while parsing the `git commit`
-- * options.
-+ * Only `-m` and `-F` are handled here. `-c`/`-C` are
-+ * incompatible with --fixup and have already errored out
-+ * during option parsing.
- */
-- if (have_option_m && !strcmp(fixup_prefix, "fixup"))
-+ if (have_option_m) {
- strbuf_addbuf(&sb, &message);
--
-- if (!strcmp(fixup_prefix, "amend")) {
-- if (have_option_m)
-- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
-+ } else if (logfile && !strcmp(logfile, "-")) {
-+ if (isatty(0))
-+ fprintf(stderr, _("(reading log message from standard input)\n"));
-+ if (strbuf_read(&sb, 0, 0) < 0)
-+ die_errno(_("could not read log from standard input"));
-+ } else if (logfile) {
-+ if (strbuf_read_file(&sb, logfile, 0) < 0)
-+ die_errno(_("could not read log file '%s'"), logfile);
-+ } else if (!strcmp(fixup_prefix, "amend")) {
- prepare_amend_commit(commit, &sb, &ctx);
- }
- } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
+ * Insert the proper subject line before other commit
@@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
}
if (fixup_message && squash_message)
2: 13608615d6 ! 3: 159a56c510 commit: allow -c/-C for all kinds of --fixup
@@ Metadata
Author: Erik Cervin-Edin <erik@cervined.in>
## Commit message ##
- commit: allow -c/-C for all kinds of --fixup
+ commit: allow -c/-C for all --fixup variants
The fixup code path in prepare_to_commit() only knows how to take a
message body from -m or -F. Now that the previous commit allows -m and
- -F for all --fixup variations, -c/-C are the odd ones out.
+ -F for all --fixup variants, -c/-C are the odd ones out.
- Teach the fixup path to look up the ref given to -c/-C and seed its
- message when preparing to amend the commit, mirroring what --fixup=amend
- does when no message source is given. With this in place, -m/-F/-c/-C
- all behave consistently across the plain, amend, and reword --fixup
- forms.
+ Teach the fixup path to take the message body from the commit given to
+ -c/-C, using prepare_amend_commit() as --fixup=amend does when no
+ message source is given.
+
+ The main motivation is consistency: with -c/-C allowed, every message
+ option works with every --fixup variant, and there's no exception to
+ document or remember. Using -c/-C under --fixup is admittedly niche,
+ but not useless; for example, rewording commit Y based on X's message
+ after an earlier rebase split X into X' and Y, when Y wasn't reworded at
+ the time:
+
+ git commit --fixup=reword:Y -c X
+
+ Like --fixup=amend, this copies only the body when the source itself is
+ an "amend!" commit. Under --fixup the subject is always generated, and
+ the body of an "amend!" commit is the message intended for its target,
+ so copying its "amend!" line would leave it in the final message after
+ autosquash. This also means that "git commit --fixup=amend:X -C X"
+ produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
+
+ Plain --fixup never opens an editor, so -c there behaves like -C.
The incompatibility check grouping -C, -c, and --fixup can go away
entirely, as -C and -c are already rejected together by the check that
@@ Documentation/git-commit.adoc: The commit created by `--fixup=amend:<commit>` is
## builtin/commit.c ##
@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
+ die_errno(_("could not read log file '%s'"),
+ logfile);
hook_arg1 = "message";
-
- /*
-- * Only `-m` and `-F` are handled here. `-c`/`-C` are
-- * incompatible with --fixup and have already errored out
-- * during option parsing.
-+ * `-m`, `-F`, `-C`, and `-c` provide the message body.
-+ * If none was given and this is an amend, use the target
-+ * commit's body instead.
- */
- if (have_option_m) {
- strbuf_addbuf(&sb, &message);
+- } else if (use_message) {
++ } else if (use_message && !fixup_message) {
+ const char *buffer;
+ buffer = strstr(use_message_buffer, "\n\n");
+ if (buffer)
@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
- } else if (logfile) {
- if (strbuf_read_file(&sb, logfile, 0) < 0)
- die_errno(_("could not read log file '%s'"), logfile);
-+ } else if (use_message) {
-+ struct commit *c = lookup_commit_reference_by_name(use_message);
-+ if (!c)
-+ die(_("could not lookup commit '%s'"), use_message);
-+ prepare_amend_commit(c, &sb, &ctx);
- } else if (!strcmp(fixup_prefix, "amend")) {
- prepare_amend_commit(commit, &sb, &ctx);
+ hook_arg1 = "commit";
+ hook_arg2 = use_message;
+ } else if (fixup_message) {
++ const char *refname = NULL;
++
+ hook_arg1 = "message";
+- if (!strcmp(fixup_prefix, "amend")) {
++ if (use_message)
++ refname = use_message;
++ else if (!strcmp(fixup_prefix, "amend"))
++ refname = fixup_commit;
++
++ if (refname) {
+ struct pretty_print_context ctx = {0};
+- struct commit *c = lookup_commit_reference_by_name(fixup_commit);
++ struct commit *c = lookup_commit_reference_by_name(refname);
++
+ if (!c)
+- die(_("could not lookup commit '%s'"), fixup_commit);
++ die(_("could not lookup commit '%s'"), refname);
+ ctx.output_encoding = get_commit_output_encoding();
+ prepare_amend_commit(c, &sb, &ctx);
}
@@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
}
@@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
+test_expect_success 'commit --fixup works with -C' '
+ commit_for_rebase_autosquash_setup &&
-+ git commit --fixup HEAD~ -C HEAD &&
++ GIT_EDITOR=false git commit --fixup HEAD~ -C HEAD &&
+ test_commit_message HEAD <<-EOF
+ fixup! $(git log -1 --format=%s HEAD~2)
+
@@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
+
+test_expect_success 'commit --fixup=amend: works with -c' '
+ commit_for_rebase_autosquash_setup &&
-+ test_set_editor : &&
-+ git commit --fixup=amend:HEAD -c HEAD~ &&
++ GIT_EDITOR="echo edited >>" git commit --fixup=amend:HEAD -c HEAD~ &&
+ test_commit_message HEAD <<-EOF
+ amend! intermediate commit
+
@@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
+
+ target message body line 1
+ target message body line 2
++
++ edited
+ EOF
+'
+
@@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
+ git log -1 --pretty=%B >with-c &&
+
+ git reset --hard "$start" &&
-+ test_set_editor : &&
+ git commit --fixup=amend:HEAD &&
+ git commit --fixup=amend:HEAD &&
+ git log -1 --pretty=%B >without-c &&
base-commit: f7de81456940dd6f3274e461149bba12965de609
--
2.56.1.978.gcc9bcf3eaa
[PATCH v4 2/3] commit: allow -m/-F for all --fixup variants
Author: Erik Cervin-Edin
Date: Tue, 24 Nov 2026 23:32
Date: Tue, 24 Nov 2026 23:32
203 lines
19320 bytes
19320 bytes
The ability to provide a commit message for git commit --fixup and its
variants is limited:
* Plain --fixup accepts -m but not -F
* The amend/reword variants accept a message only through an editor
(or a GIT_EDITOR script standing in for one)
This makes the amend/reword variants poorly suited for non-interactive
workflows -- notably when using AI coding agents.
When --fixup learned to take -m [1], it was noted that other options
(-c/-C/-F) could also be supported, but were left out for lack of a
clear use case. Later, when the amend suboption was introduced in [2],
-m was initially supported for amend fixups too, but was dropped for the
same reason [3].
The rejections of these options hark back to when --fixup was introduced
in [4], but as [1] noted, nothing inherently prevents supporting them.
The current patchwork of which options work with which --fixup variants
has no strong logic to it, and allowing all of them simplifies the
interface.
Allow -m and -F to supply the message body for all --fixup variants,
mirroring the flow of a regular commit. With --fixup=amend/reword the
given message replaces the one that would otherwise be copied from the
target commit. Options -c and -C are handled in the next commit.
1. 30884c9afc (commit: add support for --fixup <commit> -m"<extra
message>", 2017-12-22)
2. 494d314a05 (commit: add amend suboption to --fixup to create amend!
commit, 2021-03-15)
3. https://lore.kernel.org/git/xmqqft1o80pe.fsf@gitster.g/
4. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
2010-11-02)
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
---
Documentation/git-commit.adoc | 19 ++++----
builtin/commit.c | 5 +-
t/t7500-commit-template-squash-signoff.sh | 56 +++++++++++++++++------
3 files changed, 53 insertions(+), 27 deletions(-)
diff --git a/Documentation/git-commit.adoc b/Documentation/git-commit.adoc
index 8329c1034b..61efd29e66 100644
--- a/Documentation/git-commit.adoc
+++ b/Documentation/git-commit.adoc
@@ -103,20 +103,21 @@ include::diff-context-options.adoc[]
The commit created by plain `--fixup=<commit>` has a title
composed of "fixup!" followed by the title of _<commit>_,
and is recognized specially by `git rebase --autosquash`. The `-m`
-option may be used to supplement the log message of the created
-commit, but the additional commentary will be thrown away once the
-"fixup!" commit is squashed into _<commit>_ by
+or `-F` option may be used to supplement the log message
+of the created commit, but the additional commentary will be thrown
+away once the "fixup!" commit is squashed into _<commit>_ by
`git rebase --autosquash`.
+
The commit created by `--fixup=amend:<commit>` is similar but its
title is instead prefixed with "amend!". The log message of
_<commit>_ is copied into the log message of the "amend!" commit and
-opened in an editor so it can be refined. When `git rebase
---autosquash` squashes the "amend!" commit into _<commit>_, the
-log message of _<commit>_ is replaced by the refined log message
-from the "amend!" commit. It is an error for the "amend!" commit's
-log message to be empty unless `--allow-empty-message` is
-specified.
+opened in an editor so it can be refined. The replacement message may
+also be supplied directly using `-m` or `-F`, bypassing the
+need to open an editor. When `git rebase
+--autosquash` squashes the "amend!" commit into _<commit>_, the log
+message of _<commit>_ is replaced by the refined log message from the
+"amend!" commit. It is an error for the "amend!" commit's log message
+to be empty unless `--allow-empty-message` is specified.
+
`--fixup=reword:<commit>` is shorthand for `--fixup=amend:<commit>
--only`. It creates an "amend!" commit with only a log message
diff --git a/builtin/commit.c b/builtin/commit.c
index 698823d4fa..e0fac284bc 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -793,8 +793,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
repo_format_commit_message(the_repository, c, fmt, &sb,
&ctx);
free(fmt);
- if (have_option_m && !strcmp(fixup_prefix, "amend"))
- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
} else if (squash_message) {
/*
* Insert the proper subject line before other commit
@@ -1331,9 +1329,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
}
if (fixup_message && squash_message)
die(_("options '%s' and '%s' cannot be used together"), "--squash", "--fixup");
- die_for_incompatible_opt4(!!use_message, "-C",
+ die_for_incompatible_opt3(!!use_message, "-C",
!!edit_message, "-c",
- !!logfile, "-F",
!!fixup_message, "--fixup");
die_for_incompatible_opt4(have_option_m, "-m",
!!edit_message, "-c",
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 5e782ad8d7..9b2ecb1356 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -384,18 +384,24 @@ test_expect_success '--fixup=reword: ignores staged changes' '
test_cmp foo actual
'
-test_expect_success '--fixup=reword: error out with -m option' '
+test_expect_success 'commit --fixup=reword: works with -m' '
commit_for_rebase_autosquash_setup &&
- echo "fatal: options '\''-m'\'' and '\''--fixup:reword'\'' cannot be used together" >expect &&
- test_must_fail git commit --fixup=reword:HEAD~ -m "reword commit message" 2>actual &&
- test_cmp expect actual
+ git commit --fixup=reword:HEAD~ -m "reword commit message" &&
+ test_commit_message HEAD <<-EOF
+ amend! $(git log -1 --format=%s HEAD~2)
+
+ reword commit message
+ EOF
'
-test_expect_success '--fixup=amend: error out with -m option' '
+test_expect_success 'commit --fixup=amend: works with -m' '
commit_for_rebase_autosquash_setup &&
- echo "fatal: options '\''-m'\'' and '\''--fixup:amend'\'' cannot be used together" >expect &&
- test_must_fail git commit --fixup=amend:HEAD~ -m "amend commit message" 2>actual &&
- test_cmp expect actual
+ git commit --fixup=amend:HEAD~ -m "amend commit message" &&
+ test_commit_message HEAD <<-EOF
+ amend! $(git log -1 --format=%s HEAD~2)
+
+ amend commit message
+ EOF
'
test_expect_success 'consecutive amend! commits remove amend! line from commit msg body' '
@@ -432,6 +438,13 @@ test_expect_success 'deny to create amend! commit if its commit msg body is empt
test_cmp expected actual
'
+test_expect_success 'deny to create amend! commit if -m is empty' '
+ commit_for_rebase_autosquash_setup &&
+ echo "Aborting commit due to empty commit message body." >expect &&
+ test_must_fail git commit --fixup=amend:HEAD~ -m "" 2>actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'amend! commit allows empty commit msg body with --allow-empty-message' '
commit_for_rebase_autosquash_setup &&
cat >expected <<-EOF &&
@@ -468,10 +481,26 @@ test_expect_success '--fixup=reword: give error with pathsec' '
test_cmp expect actual
'
-test_expect_success '--fixup=reword: -F give error message' '
- echo "fatal: options '\''-F'\'' and '\''--fixup'\'' cannot be used together" >expect &&
- test_must_fail git commit --fixup=reword:HEAD~ -F msg 2>actual &&
- test_cmp expect actual
+test_expect_success 'commit --fixup works with -F' '
+ commit_for_rebase_autosquash_setup &&
+ echo "message" >msgfile &&
+ git commit --fixup HEAD~ -F msgfile &&
+ test_commit_message HEAD <<-EOF
+ fixup! $(git log -1 --format=%s HEAD~2)
+
+ message
+ EOF
+'
+
+test_expect_success 'commit --fixup=reword: works with -F' '
+ commit_for_rebase_autosquash_setup &&
+ echo "message from file" >msgfile &&
+ git commit --fixup=reword:HEAD~ -F msgfile &&
+ test_commit_message HEAD <<-EOF
+ amend! $(git log -1 --format=%s HEAD~2)
+
+ $(cat msgfile)
+ EOF
'
test_expect_success 'commit --squash works with -F' '
@@ -526,8 +555,7 @@ test_expect_success 'invalid message options when using --fixup' '
git add foo &&
test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -F log
+ test_must_fail git commit --fixup HEAD~1 -c HEAD~2
'
cat >expected-template <<EOF
--
2.56.1.978.gcc9bcf3eaa
[PATCH v4 3/3] commit: allow -c/-C for all --fixup variants
Author: Erik Cervin-Edin
Date: Tue, 24 Nov 2026 23:32
Date: Tue, 24 Nov 2026 23:32
193 lines
17994 bytes
17994 bytes
The fixup code path in prepare_to_commit() only knows how to take a
message body from -m or -F. Now that the previous commit allows -m and
-F for all --fixup variants, -c/-C are the odd ones out.
Teach the fixup path to take the message body from the commit given to
-c/-C, using prepare_amend_commit() as --fixup=amend does when no
message source is given.
The main motivation is consistency: with -c/-C allowed, every message
option works with every --fixup variant, and there's no exception to
document or remember. Using -c/-C under --fixup is admittedly niche,
but not useless; for example, rewording commit Y based on X's message
after an earlier rebase split X into X' and Y, when Y wasn't reworded at
the time:
git commit --fixup=reword:Y -c X
Like --fixup=amend, this copies only the body when the source itself is
an "amend!" commit. Under --fixup the subject is always generated, and
the body of an "amend!" commit is the message intended for its target,
so copying its "amend!" line would leave it in the final message after
autosquash. This also means that "git commit --fixup=amend:X -C X"
produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
Plain --fixup never opens an editor, so -c there behaves like -C.
The incompatibility check grouping -C, -c, and --fixup can go away
entirely, as -C and -c are already rejected together by the check that
groups them with -m and -F.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
---
Documentation/git-commit.adoc | 9 ++--
builtin/commit.c | 19 ++++---
t/t7500-commit-template-squash-signoff.sh | 60 +++++++++++++++++++++--
3 files changed, 74 insertions(+), 14 deletions(-)
diff --git a/Documentation/git-commit.adoc b/Documentation/git-commit.adoc
index 61efd29e66..98c50a3be5 100644
--- a/Documentation/git-commit.adoc
+++ b/Documentation/git-commit.adoc
@@ -102,8 +102,8 @@ include::diff-context-options.adoc[]
+
The commit created by plain `--fixup=<commit>` has a title
composed of "fixup!" followed by the title of _<commit>_,
-and is recognized specially by `git rebase --autosquash`. The `-m`
-or `-F` option may be used to supplement the log message
+and is recognized specially by `git rebase --autosquash`. The `-m`,
+`-F`, `-C`, or `-c` option may be used to supplement the log message
of the created commit, but the additional commentary will be thrown
away once the "fixup!" commit is squashed into _<commit>_ by
`git rebase --autosquash`.
@@ -112,8 +112,9 @@ The commit created by `--fixup=amend:<commit>` is similar but its
title is instead prefixed with "amend!". The log message of
_<commit>_ is copied into the log message of the "amend!" commit and
opened in an editor so it can be refined. The replacement message may
-also be supplied directly using `-m` or `-F`, bypassing the
-need to open an editor. When `git rebase
+also be supplied directly using `-m`, `-F`, or `-C`, bypassing the
+need to open an editor, or using `-c` to open the editor pre-populated
+with the referenced commit's message. When `git rebase
--autosquash` squashes the "amend!" commit into _<commit>_, the log
message of _<commit>_ is replaced by the refined log message from the
"amend!" commit. It is an error for the "amend!" commit's log message
diff --git a/builtin/commit.c b/builtin/commit.c
index e0fac284bc..b52ef283f2 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -827,7 +827,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
die_errno(_("could not read log file '%s'"),
logfile);
hook_arg1 = "message";
- } else if (use_message) {
+ } else if (use_message && !fixup_message) {
const char *buffer;
buffer = strstr(use_message_buffer, "\n\n");
if (buffer)
@@ -835,12 +835,20 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
hook_arg1 = "commit";
hook_arg2 = use_message;
} else if (fixup_message) {
+ const char *refname = NULL;
+
hook_arg1 = "message";
- if (!strcmp(fixup_prefix, "amend")) {
+ if (use_message)
+ refname = use_message;
+ else if (!strcmp(fixup_prefix, "amend"))
+ refname = fixup_commit;
+
+ if (refname) {
struct pretty_print_context ctx = {0};
- struct commit *c = lookup_commit_reference_by_name(fixup_commit);
+ struct commit *c = lookup_commit_reference_by_name(refname);
+
if (!c)
- die(_("could not lookup commit '%s'"), fixup_commit);
+ die(_("could not lookup commit '%s'"), refname);
ctx.output_encoding = get_commit_output_encoding();
prepare_amend_commit(c, &sb, &ctx);
}
@@ -1329,9 +1337,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
}
if (fixup_message && squash_message)
die(_("options '%s' and '%s' cannot be used together"), "--squash", "--fixup");
- die_for_incompatible_opt3(!!use_message, "-C",
- !!edit_message, "-c",
- !!fixup_message, "--fixup");
die_for_incompatible_opt4(have_option_m, "-m",
!!edit_message, "-c",
!!use_message, "-C",
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 9b2ecb1356..04520be0c3 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -492,6 +492,62 @@ test_expect_success 'commit --fixup works with -F' '
EOF
'
+test_expect_success 'commit --fixup works with -C' '
+ commit_for_rebase_autosquash_setup &&
+ GIT_EDITOR=false git commit --fixup HEAD~ -C HEAD &&
+ test_commit_message HEAD <<-EOF
+ fixup! $(git log -1 --format=%s HEAD~2)
+
+ $(get_commit_msg HEAD~)
+ EOF
+'
+
+test_expect_success 'commit --fixup=amend: works with -c' '
+ commit_for_rebase_autosquash_setup &&
+ GIT_EDITOR="echo edited >>" git commit --fixup=amend:HEAD -c HEAD~ &&
+ test_commit_message HEAD <<-EOF
+ amend! intermediate commit
+
+ target message subject line
+
+ target message body line 1
+ target message body line 2
+
+ edited
+ EOF
+'
+
+test_expect_success 'commit --fixup=amend:HEAD with -C HEAD and without have the same message' '
+ commit_for_rebase_autosquash_setup &&
+ start=$(git rev-parse HEAD) &&
+
+ git commit --fixup=amend:HEAD -C HEAD &&
+ git commit --fixup=amend:HEAD -C HEAD &&
+ git log -1 --pretty=%B >with-c &&
+
+ git reset --hard "$start" &&
+ git commit --fixup=amend:HEAD &&
+ git commit --fixup=amend:HEAD &&
+ git log -1 --pretty=%B >without-c &&
+
+ test_cmp with-c without-c
+'
+
+test_expect_success 'commit --fixup=amend: with -C copies full subject + body of squash commit' '
+ commit_for_rebase_autosquash_setup &&
+ git commit --squash HEAD~ -m "inner body" &&
+ echo "extra" >>foo &&
+ git add foo &&
+ git commit --fixup=amend:HEAD -C HEAD &&
+ test_commit_message HEAD <<-EOF
+ amend! squash! $(git log -1 --format=%s HEAD~3)
+
+ squash! $(git log -1 --format=%s HEAD~3)
+
+ inner body
+ EOF
+'
+
test_expect_success 'commit --fixup=reword: works with -F' '
commit_for_rebase_autosquash_setup &&
echo "message from file" >msgfile &&
@@ -553,9 +609,7 @@ test_expect_success 'invalid message options when using --fixup' '
echo changes >>foo &&
echo "message" >log &&
git add foo &&
- test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -c HEAD~2
+ test_must_fail git commit --fixup HEAD~1 --squash HEAD~2
'
cat >expected-template <<EOF
--
2.56.1.978.gcc9bcf3eaa
Re: [PATCH v4 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Author: Phillip Wood
Date: Wed, 25 Nov 2026 14:37
Date: Wed, 25 Nov 2026 14:37
367 lines
29162 bytes
29162 bytes
Hi Erik
On 24/11/2026 23:32, Erik Cervin-Edin wrote:
> Changes since v3:
>
> * New 1/3 refactors prepare_to_commit() to write the --fixup subject
> in a block before the message-source chain, as --squash already
> does. On v3 1/2 Phillip found it unfortunate that the -m and -F
> arms had to be guarded with "!fixup_message" while the fixup arm
> duplicated their work [1] and I agree.
>
> Originally, I wanted to avoid a refactor -- but the guards were
> getting nasty, and a refactor is the proper fix. It turned out not
> to be that difficult and I think it makes the series land cleaner.
>
> With the subject written up front, the -m and -F arms serve every
> --fixup variant unchanged, and the fixup arm is left with only the
> amend case.
This change looks good and makes the second patch much nicer. I'm happy
with everything apart from
Plain --fixup never opens an editor, so -c there behaves like -C.
in patch 3. It would be much nicer if we didn't change the meaning of
"-c" when it is combined with "--fixup". Users who do not want to edit
the message can use "-C". I've not looked at how easy it would be to fix
that. If it turns out to be tricky then I'm happy to merge this as is
and leave it as #leftoverbits.
Thanks
Phillip
> * 2/3 and 3/3 are rebuilt on top of 1/3, which now carries most of
> the change to builtin/commit.c.
>
> * 3/3 tests: took Phillip's suggestions [2].
>
> * Log messages: reworded 2/3's history of why these options were
> rejected; 3/3 now gives its motivation, with a use case, and
> explains the "amend!" handling that the v3 cover letter described.
>
> Background
> ----------
>
> Today only -m works with plain --fixup, and neither -m nor -F works
> with --fixup=amend: or --fixup=reword:, which makes those modes
> awkward to drive non-interactively. 2/3 lets -m and -F supply the
> message for all --fixup variants. 3/3 does the same for -c/-C, so
> that all four message sources behave consistently across the plain,
> amend, and reword forms.
>
> As in v3, -c/-C go through prepare_amend_commit(), so if the source
> commit is itself an "amend!" commit, its subject line is dropped and
> only the body is copied. This is what a no-source
> --fixup=amend:<commit> already does. The helper only knows about
> "amend!" and not "fixup!" or "squash!"; that is pre-existing and I
> have left it alone here.
>
> The earlier rounds are described in the v2 [3] and v3 [4] cover
> letters.
>
> [1] https://lore.kernel.org/git/3354eeb4-3b9d-474e-bf9f-8efd2ca3a512@gmail.com/
> [2] https://lore.kernel.org/git/de12af28-a64e-4472-8bd4-b65200772dbe@gmail.com/
> [3] https://lore.kernel.org/git/cover.1779792311.git.erik@cervined.in/
> [4] https://lore.kernel.org/git/cover.1790082176.git.erik@cervined.in/
>
> Erik Cervin-Edin (3):
> commit: write the --fixup subject the way --squash does
> commit: allow -m/-F for all --fixup variants
> commit: allow -c/-C for all --fixup variants
>
> Documentation/git-commit.adoc | 22 +++--
> builtin/commit.c | 61 ++++++------
> t/t7500-commit-template-squash-signoff.sh | 114 +++++++++++++++++++---
> 3 files changed, 138 insertions(+), 59 deletions(-)
>
> Range-diff against v3:
> -: ---------- > 1: ebae1fbe05 commit: write the --fixup subject the way --squash does
> 1: 4a493867bb ! 2: 051b659965 commit: allow -m/-F for all kinds of --fixup
> @@ Metadata
> Author: Erik Cervin-Edin <erik@cervined.in>
>
> ## Commit message ##
> - commit: allow -m/-F for all kinds of --fixup
> + commit: allow -m/-F for all --fixup variants
>
> The ability to provide a commit message for git commit --fixup and its
> - variations is limited:
> + variants is limited:
>
> - * Plain --fixup only allows using the -m flag
> + * Plain --fixup accepts -m but not -F
>
> - * The amend/reword --fixup variants only allow supplying the message
> - using an editor
> + * The amend/reword variants accept a message only through an editor
> + (or a GIT_EDITOR script standing in for one)
>
> - For amend/reword, the -m and -F flags are rejected: -m is caught by a
> - die() in prepare_to_commit(), and -F is caught by
> - die_for_incompatible_opt4() which groups -F with --fixup as mutually
> - exclusive. This makes these modes poorly suited for non-interactive
> + This makes the amend/reword variants poorly suited for non-interactive
> workflows -- notably when using AI coding agents.
>
> - When support to use the -m option was introduced in [1] it was noted
> - that there could be support for other options but at the time the use
> - case was deemed too niche. Later, when the amend suboption was
> - introduced in [2] -m support for amend fixups was discussed but not
> - pursued, and -F was already caught by the higher-layer incompatibility
> - check grouping it with --fixup.
> + When --fixup learned to take -m [1], it was noted that other options
> + (-c/-C/-F) could also be supported, but were left out for lack of a
> + clear use case. Later, when the amend suboption was introduced in [2],
> + -m was initially supported for amend fixups too, but was dropped for the
> + same reason [3].
>
> - The rejections of these options hark back to when --fixup was
> - introduced in [3] and as noted in [1] -- there's nothing inherently
> - preventing support for them. The current patchwork of which flags
> - work with which --fixup variants has no strong logic to it, and
> - allowing all of them simplifies both the code and the interface.
> + The rejections of these options hark back to when --fixup was introduced
> + in [4], but as [1] noted, nothing inherently prevents supporting them.
>
> - Allow -m and -F to supply the message body for all --fixup variations,
> - mirroring the flow of a regular commit. -c and -C, which are blocked
> - by the same incompatibility check, are handled in the next commit.
> + The current patchwork of which options work with which --fixup variants
> + has no strong logic to it, and allowing all of them simplifies the
> + interface.
> +
> + Allow -m and -F to supply the message body for all --fixup variants,
> + mirroring the flow of a regular commit. With --fixup=amend/reword the
> + given message replaces the one that would otherwise be copied from the
> + target commit. Options -c and -C are handled in the next commit.
>
> 1. 30884c9afc (commit: add support for --fixup <commit> -m"<extra
> message>", 2017-12-22)
> @@ Commit message
> 2. 494d314a05 (commit: add amend suboption to --fixup to create amend!
> commit, 2021-03-15)
>
> - 3. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
> + 3. https://lore.kernel.org/git/xmqqft1o80pe.fsf@gitster.g/
> +
> + 4. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
> 2010-11-02)
>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> - Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
> + Helped-by: Phillip Wood <phillip.wood123@gmail.com>
> Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
>
> ## Documentation/git-commit.adoc ##
> @@ Documentation/git-commit.adoc: include::diff-context-options.adoc[]
>
> ## builtin/commit.c ##
> @@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
> - if (have_option_m && !fixup_message) {
> - strbuf_addbuf(&sb, &message);
> - hook_arg1 = "message";
> -- } else if (logfile && !strcmp(logfile, "-")) {
> -+ } else if (logfile && !fixup_message && !strcmp(logfile, "-")) {
> - if (isatty(0))
> - fprintf(stderr, _("(reading log message from standard input)\n"));
> - if (strbuf_read(&sb, 0, 0) < 0)
> - die_errno(_("could not read log from standard input"));
> - hook_arg1 = "message";
> -- } else if (logfile) {
> -+ } else if (logfile && !fixup_message) {
> - if (strbuf_read_file(&sb, logfile, 0) < 0)
> - die_errno(_("could not read log file '%s'"),
> - logfile);
> - hook_arg1 = "message";
> -- } else if (use_message) {
> -+ } else if (use_message && !fixup_message) {
> - const char *buffer;
> - buffer = strstr(use_message_buffer, "\n\n");
> - if (buffer)
> -@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
> - hook_arg1 = "message";
> -
> + repo_format_commit_message(the_repository, c, fmt, &sb,
> + &ctx);
> + free(fmt);
> +- if (have_option_m && !strcmp(fixup_prefix, "amend"))
> +- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> + } else if (squash_message) {
> /*
> -- * Only `-m` commit message option is checked here, as
> -- * it supports `--fixup` to append the commit message.
> -- *
> -- * The other commit message options `-c`/`-C`/`-F` are
> -- * incompatible with all the forms of `--fixup` and
> -- * have already errored out while parsing the `git commit`
> -- * options.
> -+ * Only `-m` and `-F` are handled here. `-c`/`-C` are
> -+ * incompatible with --fixup and have already errored out
> -+ * during option parsing.
> - */
> -- if (have_option_m && !strcmp(fixup_prefix, "fixup"))
> -+ if (have_option_m) {
> - strbuf_addbuf(&sb, &message);
> --
> -- if (!strcmp(fixup_prefix, "amend")) {
> -- if (have_option_m)
> -- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> -+ } else if (logfile && !strcmp(logfile, "-")) {
> -+ if (isatty(0))
> -+ fprintf(stderr, _("(reading log message from standard input)\n"));
> -+ if (strbuf_read(&sb, 0, 0) < 0)
> -+ die_errno(_("could not read log from standard input"));
> -+ } else if (logfile) {
> -+ if (strbuf_read_file(&sb, logfile, 0) < 0)
> -+ die_errno(_("could not read log file '%s'"), logfile);
> -+ } else if (!strcmp(fixup_prefix, "amend")) {
> - prepare_amend_commit(commit, &sb, &ctx);
> - }
> - } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
> + * Insert the proper subject line before other commit
> @@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
> }
> if (fixup_message && squash_message)
> 2: 13608615d6 ! 3: 159a56c510 commit: allow -c/-C for all kinds of --fixup
> @@ Metadata
> Author: Erik Cervin-Edin <erik@cervined.in>
>
> ## Commit message ##
> - commit: allow -c/-C for all kinds of --fixup
> + commit: allow -c/-C for all --fixup variants
>
> The fixup code path in prepare_to_commit() only knows how to take a
> message body from -m or -F. Now that the previous commit allows -m and
> - -F for all --fixup variations, -c/-C are the odd ones out.
> + -F for all --fixup variants, -c/-C are the odd ones out.
>
> - Teach the fixup path to look up the ref given to -c/-C and seed its
> - message when preparing to amend the commit, mirroring what --fixup=amend
> - does when no message source is given. With this in place, -m/-F/-c/-C
> - all behave consistently across the plain, amend, and reword --fixup
> - forms.
> + Teach the fixup path to take the message body from the commit given to
> + -c/-C, using prepare_amend_commit() as --fixup=amend does when no
> + message source is given.
> +
> + The main motivation is consistency: with -c/-C allowed, every message
> + option works with every --fixup variant, and there's no exception to
> + document or remember. Using -c/-C under --fixup is admittedly niche,
> + but not useless; for example, rewording commit Y based on X's message
> + after an earlier rebase split X into X' and Y, when Y wasn't reworded at
> + the time:
> +
> + git commit --fixup=reword:Y -c X
> +
> + Like --fixup=amend, this copies only the body when the source itself is
> + an "amend!" commit. Under --fixup the subject is always generated, and
> + the body of an "amend!" commit is the message intended for its target,
> + so copying its "amend!" line would leave it in the final message after
> + autosquash. This also means that "git commit --fixup=amend:X -C X"
> + produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
> +
> + Plain --fixup never opens an editor, so -c there behaves like -C.
>
> The incompatibility check grouping -C, -c, and --fixup can go away
> entirely, as -C and -c are already rejected together by the check that
> @@ Documentation/git-commit.adoc: The commit created by `--fixup=amend:<commit>` is
>
> ## builtin/commit.c ##
> @@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
> + die_errno(_("could not read log file '%s'"),
> + logfile);
> hook_arg1 = "message";
> -
> - /*
> -- * Only `-m` and `-F` are handled here. `-c`/`-C` are
> -- * incompatible with --fixup and have already errored out
> -- * during option parsing.
> -+ * `-m`, `-F`, `-C`, and `-c` provide the message body.
> -+ * If none was given and this is an amend, use the target
> -+ * commit's body instead.
> - */
> - if (have_option_m) {
> - strbuf_addbuf(&sb, &message);
> +- } else if (use_message) {
> ++ } else if (use_message && !fixup_message) {
> + const char *buffer;
> + buffer = strstr(use_message_buffer, "\n\n");
> + if (buffer)
> @@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
> - } else if (logfile) {
> - if (strbuf_read_file(&sb, logfile, 0) < 0)
> - die_errno(_("could not read log file '%s'"), logfile);
> -+ } else if (use_message) {
> -+ struct commit *c = lookup_commit_reference_by_name(use_message);
> -+ if (!c)
> -+ die(_("could not lookup commit '%s'"), use_message);
> -+ prepare_amend_commit(c, &sb, &ctx);
> - } else if (!strcmp(fixup_prefix, "amend")) {
> - prepare_amend_commit(commit, &sb, &ctx);
> + hook_arg1 = "commit";
> + hook_arg2 = use_message;
> + } else if (fixup_message) {
> ++ const char *refname = NULL;
> ++
> + hook_arg1 = "message";
> +- if (!strcmp(fixup_prefix, "amend")) {
> ++ if (use_message)
> ++ refname = use_message;
> ++ else if (!strcmp(fixup_prefix, "amend"))
> ++ refname = fixup_commit;
> ++
> ++ if (refname) {
> + struct pretty_print_context ctx = {0};
> +- struct commit *c = lookup_commit_reference_by_name(fixup_commit);
> ++ struct commit *c = lookup_commit_reference_by_name(refname);
> ++
> + if (!c)
> +- die(_("could not lookup commit '%s'"), fixup_commit);
> ++ die(_("could not lookup commit '%s'"), refname);
> + ctx.output_encoding = get_commit_output_encoding();
> + prepare_amend_commit(c, &sb, &ctx);
> }
> @@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
> }
> @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
>
> +test_expect_success 'commit --fixup works with -C' '
> + commit_for_rebase_autosquash_setup &&
> -+ git commit --fixup HEAD~ -C HEAD &&
> ++ GIT_EDITOR=false git commit --fixup HEAD~ -C HEAD &&
> + test_commit_message HEAD <<-EOF
> + fixup! $(git log -1 --format=%s HEAD~2)
> +
> @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
> +
> +test_expect_success 'commit --fixup=amend: works with -c' '
> + commit_for_rebase_autosquash_setup &&
> -+ test_set_editor : &&
> -+ git commit --fixup=amend:HEAD -c HEAD~ &&
> ++ GIT_EDITOR="echo edited >>" git commit --fixup=amend:HEAD -c HEAD~ &&
> + test_commit_message HEAD <<-EOF
> + amend! intermediate commit
> +
> @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
> +
> + target message body line 1
> + target message body line 2
> ++
> ++ edited
> + EOF
> +'
> +
> @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup w
> + git log -1 --pretty=%B >with-c &&
> +
> + git reset --hard "$start" &&
> -+ test_set_editor : &&
> + git commit --fixup=amend:HEAD &&
> + git commit --fixup=amend:HEAD &&
> + git log -1 --pretty=%B >without-c &&
>
> base-commit: f7de81456940dd6f3274e461149bba12965de609
Re: [PATCH v4 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Author: erik88
Date: Thu, 26 Nov 2026 09:17
Date: Thu, 26 Nov 2026 09:17
74 lines
13516 bytes
13516 bytes
On 25/11/26 14:37, Phillip Wood wrote:
> Hi Erik
>
> On 24/11/2026 23:32, Erik Cervin-Edin wrote:
> > Changes since v3:
> >
> > * New 1/3 refactors prepare_to_commit() to write the --fixup subject
> > in a block before the message-source chain, as --squash already
> > does. On v3 1/2 Phillip found it unfortunate that the -m and -F
> > arms had to be guarded with "!fixup_message" while the fixup arm
> > duplicated their work [1] and I agree.
> >
> > Originally, I wanted to avoid a refactor -- but the guards were
> > getting nasty, and a refactor is the proper fix. It turned out not
> > to be that difficult and I think it makes the series land cleaner.
> >
> > With the subject written up front, the -m and -F arms serve every
> > --fixup variant unchanged, and the fixup arm is left with only the
> > amend case.
>
> This change looks good and makes the second patch much nicer. I'm happy with
> everything apart from
>
> Plain --fixup never opens an editor, so -c there behaves like -C.
>
> in patch 3. It would be much nicer if we didn't change the meaning of "-c"
> when it is combined with "--fixup". Users who do not want to edit the
> message can use "-C". I've not looked at how easy it would be to fix that.
> If it turns out to be tricky then I'm happy to merge this as is and leave it
> as #leftoverbits.
That's fair. I suspect nobody will use plain --fixup with -c but it's
inconsistent if all of a sudden it means -C just because the --fixup is
plain. What should work under v4s patch 3 is --fixup -c --edit, but
forcing that is a bit weird.
> I've not looked at how easy it would be to fix that.
Looks easy enough, -c sets edit_message in cmd_commit()
OPT_STRING('c', "reedit-message", &edit_message, N_("commit"),
N_("reuse and edit message from specified commit")),
so it's already set when we reach
if (fixup_message) {
in parse_and_validate_options(), and we could probably change
} else {
fixup_commit = fixup_message;
fixup_prefix = "fixup";
use_editor = 0;
}
to
} else {
fixup_commit = fixup_message;
fixup_prefix = "fixup";
if (!edit_message)
use_editor = 0;
}
I can reroll with something like that if that seems better.
Given that the rest of the series tries to get rid of some of the
somewhat arbitrary restrictions on which options can be interchanged with
the other ones, it doesn't make much sense to me to introduce a new
"by the way, if you use -c with --fixup we'll assume you meant -C"
caveat.
To me it makes sense to keep the meaning of -c consistent.
Re: [PATCH v4 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Author: Phillip Wood
Date: Thu, 26 Nov 2026 15:07
Date: Thu, 26 Nov 2026 15:07
67 lines
12907 bytes
12907 bytes
Hi Erik
On 26/11/2026 09:17, erik88 wrote:
> On 25/11/26 14:37, Phillip Wood wrote:
>>
>> I'm happy with everything apart from
>>
>> Plain --fixup never opens an editor, so -c there behaves like -C.
>>
>> in patch 3. It would be much nicer if we didn't change the meaning of "-c"
>> when it is combined with "--fixup". Users who do not want to edit the
>> message can use "-C". I've not looked at how easy it would be to fix that.
>> If it turns out to be tricky then I'm happy to merge this as is and leave it
>> as #leftoverbits.
>
> That's fair. I suspect nobody will use plain --fixup with -c but it's
> inconsistent if all of a sudden it means -C just because the --fixup is
> plain. What should work under v4s patch 3 is --fixup -c --edit, but
> forcing that is a bit weird.
>
>> I've not looked at how easy it would be to fix that.
>
> Looks easy enough, -c sets edit_message in cmd_commit()
>
> OPT_STRING('c', "reedit-message", &edit_message, N_("commit"),
> N_("reuse and edit message from specified commit")),
>
> so it's already set when we reach
>
> if (fixup_message) {
>
> in parse_and_validate_options(), and we could probably change
>
> } else {
> fixup_commit = fixup_message;
> fixup_prefix = "fixup";
> use_editor = 0;
> }
>
> to
>
> } else {
> fixup_commit = fixup_message;
> fixup_prefix = "fixup";
> if (!edit_message)
> use_editor = 0;
> }
Oh, that's easier than I feared it might be
> I can reroll with something like that if that seems better.
>
> Given that the rest of the series tries to get rid of some of the
> somewhat arbitrary restrictions on which options can be interchanged with
> the other ones, it doesn't make much sense to me to introduce a new
> "by the way, if you use -c with --fixup we'll assume you meant -C"
> caveat.
>
> To me it makes sense to keep the meaning of -c consistent.
I agree that keeping the meaning of -c consistent would be preferable if
you're happy to re-roll
Thanks
Phillip
[PATCH v5 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Author: Erik Cervin-Edin
Date: Sat, 28 Nov 2026 12:13
Date: Sat, 28 Nov 2026 12:13
81 lines
13845 bytes
13845 bytes
Changes since v4:
* 3/3: plain --fixup -c now opens the editor, as -c does everywhere
else. v4 kept plain --fixup's existing no-editor behavior, which
meant -c silently acted like -C.
Background
----------
Today only -m works with plain --fixup, and neither -m nor -F works
with --fixup=amend: or --fixup=reword:, which makes those modes
awkward to drive non-interactively.
* 1/3 is a preparatory refactor that writes the --fixup subject before
choosing the message source, like --squash does.
* 2/3 lets -m and -F supply the message for all --fixup variants.
* 3/3 does the same for -c/-C, so that all four message sources behave
consistently across the plain, amend, and reword forms.
As in v3 and v4, -c/-C go through prepare_amend_commit(), so if
the source commit is itself an "amend!" commit, its subject line is
dropped and only the body is copied. This is what a no-source
--fixup=amend:<commit> already does. The helper only knows about
"amend!" and not "fixup!" or "squash!"; that is pre-existing and I have
left it alone here.
The earlier rounds are described in the v2 [1], v3 [2] and v4 [3]
cover letters.
[1] https://lore.kernel.org/git/cover.1779792311.git.erik@cervined.in/
[2] https://lore.kernel.org/git/cover.1790082176.git.erik@cervined.in/
[3] https://lore.kernel.org/git/cover.1795562078.git.erik@cervined.in/
Erik Cervin-Edin (3):
commit: write the --fixup subject the way --squash does
commit: allow -m/-F for all --fixup variants
commit: allow -c/-C for all --fixup variants
Documentation/git-commit.adoc | 22 +++--
builtin/commit.c | 64 ++++++------
t/t7500-commit-template-squash-signoff.sh | 114 +++++++++++++++++++---
3 files changed, 140 insertions(+), 60 deletions(-)
Range-diff against v4:
1: ebae1fbe05 = 1: ebae1fbe05 commit: write the --fixup subject the way --squash does
2: 051b659965 = 2: 051b659965 commit: allow -m/-F for all --fixup variants
3: 159a56c510 ! 3: 9ab3665cfc commit: allow -c/-C for all --fixup variants
@@ Commit message
autosquash. This also means that "git commit --fixup=amend:X -C X"
produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
- Plain --fixup never opens an editor, so -c there behaves like -C.
+ Plain --fixup turns the editor off. Keep it on when using -c, so that
+ -c isn't silently treated like -C.
The incompatibility check grouping -C, -c, and --fixup can go away
entirely, as -C and -c are already rejected together by the check that
@@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *ar
die_for_incompatible_opt4(have_option_m, "-m",
!!edit_message, "-c",
!!use_message, "-C",
+@@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
+ } else {
+ fixup_commit = fixup_message;
+ fixup_prefix = "fixup";
+- use_editor = 0;
++ if (!edit_message)
++ use_editor = 0;
+ }
+ }
+
## t/t7500-commit-template-squash-signoff.sh ##
@@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup works with -F' '
base-commit: f7de81456940dd6f3274e461149bba12965de609
--
2.56.1.978.gcc9bcf3eaa
[PATCH v5 1/3] commit: write the --fixup subject the way --squash does
Author: Erik Cervin-Edin
Date: Sat, 28 Nov 2026 12:13
Date: Sat, 28 Nov 2026 12:13
122 lines
15475 bytes
15475 bytes
In prepare_to_commit(), the source of the message is chosen by an
if/else-if chain, one arm per option. Originally [1], when using
--fixup you couldn't specify a message source, but then [2] taught
commit how to combine --fixup with -m. Since then, the -m arm is
skipped for fixup commits and instead the fixup arm writes the
"fixup!" or "amend!" subject, appending any -m messages to a "fixup!".
Unlike --fixup, --squash has supported all message source options since
it was introduced [3]. It writes its "squash!" subject first and then
lets the chain write the rest of the message.
Two commits that follow teach commit --fixup how to take messages like
--squash. In preparation for that, refactor prepare_to_commit() to
write the --fixup subject in a block before the chain, as --squash does.
Since the two options are mutually exclusive, put each subject block in
its own branch of an if/else-if.
The fixup arm is left with the one message source that takes no
command-line option: an amend, which supplies the message by opening
an editor prefilled with the fixup target's message.
The -m arm now runs before the fixup arm, so the error for -m with an
amend would never be reached there. Raise it in the subject block.
While moving the subject code, rename its "commit" variable to "c" to
match the --squash block.
1. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
2010-11-02)
2. 30884c9afc (commit: add support for --fixup <commit> -m"<extra
message>", 2017-12-22)
3. 89ac1223c0 (commit: --squash option for use with rebase --autosquash,
2010-11-02)
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
---
builtin/commit.c | 51 +++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 29 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 36e47e18ed..698823d4fa 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -781,7 +781,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
"pre-commit", NULL))
return 0;
- if (squash_message) {
+ if (fixup_message) {
+ struct pretty_print_context ctx = {0};
+ struct commit *c;
+ char *fmt;
+ c = lookup_commit_reference_by_name(fixup_commit);
+ if (!c)
+ die(_("could not lookup commit '%s'"), fixup_commit);
+ ctx.output_encoding = get_commit_output_encoding();
+ fmt = xstrfmt("%s! %%s\n\n", fixup_prefix);
+ repo_format_commit_message(the_repository, c, fmt, &sb,
+ &ctx);
+ free(fmt);
+ if (have_option_m && !strcmp(fixup_prefix, "amend"))
+ die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
+ } else if (squash_message) {
/*
* Insert the proper subject line before other commit
* message options add their content.
@@ -801,7 +815,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
}
}
- if (have_option_m && !fixup_message) {
+ if (have_option_m) {
strbuf_addbuf(&sb, &message);
hook_arg1 = "message";
} else if (logfile && !strcmp(logfile, "-")) {
@@ -823,35 +837,14 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
hook_arg1 = "commit";
hook_arg2 = use_message;
} else if (fixup_message) {
- struct pretty_print_context ctx = {0};
- struct commit *commit;
- char *fmt;
- commit = lookup_commit_reference_by_name(fixup_commit);
- if (!commit)
- die(_("could not lookup commit '%s'"), fixup_commit);
- ctx.output_encoding = get_commit_output_encoding();
- fmt = xstrfmt("%s! %%s\n\n", fixup_prefix);
- repo_format_commit_message(the_repository, commit, fmt, &sb,
- &ctx);
- free(fmt);
hook_arg1 = "message";
-
- /*
- * Only `-m` commit message option is checked here, as
- * it supports `--fixup` to append the commit message.
- *
- * The other commit message options `-c`/`-C`/`-F` are
- * incompatible with all the forms of `--fixup` and
- * have already errored out while parsing the `git commit`
- * options.
- */
- if (have_option_m && !strcmp(fixup_prefix, "fixup"))
- strbuf_addbuf(&sb, &message);
-
if (!strcmp(fixup_prefix, "amend")) {
- if (have_option_m)
- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
- prepare_amend_commit(commit, &sb, &ctx);
+ struct pretty_print_context ctx = {0};
+ struct commit *c = lookup_commit_reference_by_name(fixup_commit);
+ if (!c)
+ die(_("could not lookup commit '%s'"), fixup_commit);
+ ctx.output_encoding = get_commit_output_encoding();
+ prepare_amend_commit(c, &sb, &ctx);
}
} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
size_t merge_msg_start;
--
2.56.1.978.gcc9bcf3eaa
[PATCH v5 2/3] commit: allow -m/-F for all --fixup variants
Author: Erik Cervin-Edin
Date: Sat, 28 Nov 2026 12:14
Date: Sat, 28 Nov 2026 12:14
203 lines
19292 bytes
19292 bytes
The ability to provide a commit message for git commit --fixup and its
variants is limited:
* Plain --fixup accepts -m but not -F
* The amend/reword variants accept a message only through an editor
(or a GIT_EDITOR script standing in for one)
This makes the amend/reword variants poorly suited for non-interactive
workflows -- notably when using AI coding agents.
When --fixup learned to take -m [1], it was noted that other options
(-c/-C/-F) could also be supported, but were left out for lack of a
clear use case. Later, when the amend suboption was introduced in [2],
-m was initially supported for amend fixups too, but was dropped for the
same reason [3].
The rejections of these options hark back to when --fixup was introduced
in [4], but as [1] noted, nothing inherently prevents supporting them.
The current patchwork of which options work with which --fixup variants
has no strong logic to it, and allowing all of them simplifies the
interface.
Allow -m and -F to supply the message body for all --fixup variants,
mirroring the flow of a regular commit. With --fixup=amend/reword the
given message replaces the one that would otherwise be copied from the
target commit. Options -c and -C are handled in the next commit.
1. 30884c9afc (commit: add support for --fixup <commit> -m"<extra
message>", 2017-12-22)
2. 494d314a05 (commit: add amend suboption to --fixup to create amend!
commit, 2021-03-15)
3. https://lore.kernel.org/git/xmqqft1o80pe.fsf@gitster.g/
4. d71b8ba7c9 (commit: --fixup option for use with rebase --autosquash,
2010-11-02)
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
---
Documentation/git-commit.adoc | 19 ++++----
builtin/commit.c | 5 +-
t/t7500-commit-template-squash-signoff.sh | 56 +++++++++++++++++------
3 files changed, 53 insertions(+), 27 deletions(-)
diff --git a/Documentation/git-commit.adoc b/Documentation/git-commit.adoc
index 8329c1034b..61efd29e66 100644
--- a/Documentation/git-commit.adoc
+++ b/Documentation/git-commit.adoc
@@ -103,20 +103,21 @@ include::diff-context-options.adoc[]
The commit created by plain `--fixup=<commit>` has a title
composed of "fixup!" followed by the title of _<commit>_,
and is recognized specially by `git rebase --autosquash`. The `-m`
-option may be used to supplement the log message of the created
-commit, but the additional commentary will be thrown away once the
-"fixup!" commit is squashed into _<commit>_ by
+or `-F` option may be used to supplement the log message
+of the created commit, but the additional commentary will be thrown
+away once the "fixup!" commit is squashed into _<commit>_ by
`git rebase --autosquash`.
+
The commit created by `--fixup=amend:<commit>` is similar but its
title is instead prefixed with "amend!". The log message of
_<commit>_ is copied into the log message of the "amend!" commit and
-opened in an editor so it can be refined. When `git rebase
---autosquash` squashes the "amend!" commit into _<commit>_, the
-log message of _<commit>_ is replaced by the refined log message
-from the "amend!" commit. It is an error for the "amend!" commit's
-log message to be empty unless `--allow-empty-message` is
-specified.
+opened in an editor so it can be refined. The replacement message may
+also be supplied directly using `-m` or `-F`, bypassing the
+need to open an editor. When `git rebase
+--autosquash` squashes the "amend!" commit into _<commit>_, the log
+message of _<commit>_ is replaced by the refined log message from the
+"amend!" commit. It is an error for the "amend!" commit's log message
+to be empty unless `--allow-empty-message` is specified.
+
`--fixup=reword:<commit>` is shorthand for `--fixup=amend:<commit>
--only`. It creates an "amend!" commit with only a log message
diff --git a/builtin/commit.c b/builtin/commit.c
index 698823d4fa..e0fac284bc 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -793,8 +793,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
repo_format_commit_message(the_repository, c, fmt, &sb,
&ctx);
free(fmt);
- if (have_option_m && !strcmp(fixup_prefix, "amend"))
- die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
} else if (squash_message) {
/*
* Insert the proper subject line before other commit
@@ -1331,9 +1329,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
}
if (fixup_message && squash_message)
die(_("options '%s' and '%s' cannot be used together"), "--squash", "--fixup");
- die_for_incompatible_opt4(!!use_message, "-C",
+ die_for_incompatible_opt3(!!use_message, "-C",
!!edit_message, "-c",
- !!logfile, "-F",
!!fixup_message, "--fixup");
die_for_incompatible_opt4(have_option_m, "-m",
!!edit_message, "-c",
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 5e782ad8d7..9b2ecb1356 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -384,18 +384,24 @@ test_expect_success '--fixup=reword: ignores staged changes' '
test_cmp foo actual
'
-test_expect_success '--fixup=reword: error out with -m option' '
+test_expect_success 'commit --fixup=reword: works with -m' '
commit_for_rebase_autosquash_setup &&
- echo "fatal: options '\''-m'\'' and '\''--fixup:reword'\'' cannot be used together" >expect &&
- test_must_fail git commit --fixup=reword:HEAD~ -m "reword commit message" 2>actual &&
- test_cmp expect actual
+ git commit --fixup=reword:HEAD~ -m "reword commit message" &&
+ test_commit_message HEAD <<-EOF
+ amend! $(git log -1 --format=%s HEAD~2)
+
+ reword commit message
+ EOF
'
-test_expect_success '--fixup=amend: error out with -m option' '
+test_expect_success 'commit --fixup=amend: works with -m' '
commit_for_rebase_autosquash_setup &&
- echo "fatal: options '\''-m'\'' and '\''--fixup:amend'\'' cannot be used together" >expect &&
- test_must_fail git commit --fixup=amend:HEAD~ -m "amend commit message" 2>actual &&
- test_cmp expect actual
+ git commit --fixup=amend:HEAD~ -m "amend commit message" &&
+ test_commit_message HEAD <<-EOF
+ amend! $(git log -1 --format=%s HEAD~2)
+
+ amend commit message
+ EOF
'
test_expect_success 'consecutive amend! commits remove amend! line from commit msg body' '
@@ -432,6 +438,13 @@ test_expect_success 'deny to create amend! commit if its commit msg body is empt
test_cmp expected actual
'
+test_expect_success 'deny to create amend! commit if -m is empty' '
+ commit_for_rebase_autosquash_setup &&
+ echo "Aborting commit due to empty commit message body." >expect &&
+ test_must_fail git commit --fixup=amend:HEAD~ -m "" 2>actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'amend! commit allows empty commit msg body with --allow-empty-message' '
commit_for_rebase_autosquash_setup &&
cat >expected <<-EOF &&
@@ -468,10 +481,26 @@ test_expect_success '--fixup=reword: give error with pathsec' '
test_cmp expect actual
'
-test_expect_success '--fixup=reword: -F give error message' '
- echo "fatal: options '\''-F'\'' and '\''--fixup'\'' cannot be used together" >expect &&
- test_must_fail git commit --fixup=reword:HEAD~ -F msg 2>actual &&
- test_cmp expect actual
+test_expect_success 'commit --fixup works with -F' '
+ commit_for_rebase_autosquash_setup &&
+ echo "message" >msgfile &&
+ git commit --fixup HEAD~ -F msgfile &&
+ test_commit_message HEAD <<-EOF
+ fixup! $(git log -1 --format=%s HEAD~2)
+
+ message
+ EOF
+'
+
+test_expect_success 'commit --fixup=reword: works with -F' '
+ commit_for_rebase_autosquash_setup &&
+ echo "message from file" >msgfile &&
+ git commit --fixup=reword:HEAD~ -F msgfile &&
+ test_commit_message HEAD <<-EOF
+ amend! $(git log -1 --format=%s HEAD~2)
+
+ $(cat msgfile)
+ EOF
'
test_expect_success 'commit --squash works with -F' '
@@ -526,8 +555,7 @@ test_expect_success 'invalid message options when using --fixup' '
git add foo &&
test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -F log
+ test_must_fail git commit --fixup HEAD~1 -c HEAD~2
'
cat >expected-template <<EOF
--
2.56.1.978.gcc9bcf3eaa
[PATCH v5 3/3] commit: allow -c/-C for all --fixup variants
Author: Erik Cervin-Edin
Date: Sat, 28 Nov 2026 12:14
Date: Sat, 28 Nov 2026 12:14
204 lines
18622 bytes
18622 bytes
The fixup code path in prepare_to_commit() only knows how to take a
message body from -m or -F. Now that the previous commit allows -m and
-F for all --fixup variants, -c/-C are the odd ones out.
Teach the fixup path to take the message body from the commit given to
-c/-C, using prepare_amend_commit() as --fixup=amend does when no
message source is given.
The main motivation is consistency: with -c/-C allowed, every message
option works with every --fixup variant, and there's no exception to
document or remember. Using -c/-C under --fixup is admittedly niche,
but not useless; for example, rewording commit Y based on X's message
after an earlier rebase split X into X' and Y, when Y wasn't reworded at
the time:
git commit --fixup=reword:Y -c X
Like --fixup=amend, this copies only the body when the source itself is
an "amend!" commit. Under --fixup the subject is always generated, and
the body of an "amend!" commit is the message intended for its target,
so copying its "amend!" line would leave it in the final message after
autosquash. This also means that "git commit --fixup=amend:X -C X"
produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
Plain --fixup turns the editor off. Keep it on when using -c, so that
-c isn't silently treated like -C.
The incompatibility check grouping -C, -c, and --fixup can go away
entirely, as -C and -c are already rejected together by the check that
groups them with -m and -F.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
---
Documentation/git-commit.adoc | 9 ++--
builtin/commit.c | 22 ++++++---
t/t7500-commit-template-squash-signoff.sh | 60 +++++++++++++++++++++--
3 files changed, 76 insertions(+), 15 deletions(-)
diff --git a/Documentation/git-commit.adoc b/Documentation/git-commit.adoc
index 61efd29e66..98c50a3be5 100644
--- a/Documentation/git-commit.adoc
+++ b/Documentation/git-commit.adoc
@@ -102,8 +102,8 @@ include::diff-context-options.adoc[]
+
The commit created by plain `--fixup=<commit>` has a title
composed of "fixup!" followed by the title of _<commit>_,
-and is recognized specially by `git rebase --autosquash`. The `-m`
-or `-F` option may be used to supplement the log message
+and is recognized specially by `git rebase --autosquash`. The `-m`,
+`-F`, `-C`, or `-c` option may be used to supplement the log message
of the created commit, but the additional commentary will be thrown
away once the "fixup!" commit is squashed into _<commit>_ by
`git rebase --autosquash`.
@@ -112,8 +112,9 @@ The commit created by `--fixup=amend:<commit>` is similar but its
title is instead prefixed with "amend!". The log message of
_<commit>_ is copied into the log message of the "amend!" commit and
opened in an editor so it can be refined. The replacement message may
-also be supplied directly using `-m` or `-F`, bypassing the
-need to open an editor. When `git rebase
+also be supplied directly using `-m`, `-F`, or `-C`, bypassing the
+need to open an editor, or using `-c` to open the editor pre-populated
+with the referenced commit's message. When `git rebase
--autosquash` squashes the "amend!" commit into _<commit>_, the log
message of _<commit>_ is replaced by the refined log message from the
"amend!" commit. It is an error for the "amend!" commit's log message
diff --git a/builtin/commit.c b/builtin/commit.c
index e0fac284bc..2649506828 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -827,7 +827,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
die_errno(_("could not read log file '%s'"),
logfile);
hook_arg1 = "message";
- } else if (use_message) {
+ } else if (use_message && !fixup_message) {
const char *buffer;
buffer = strstr(use_message_buffer, "\n\n");
if (buffer)
@@ -835,12 +835,20 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
hook_arg1 = "commit";
hook_arg2 = use_message;
} else if (fixup_message) {
+ const char *refname = NULL;
+
hook_arg1 = "message";
- if (!strcmp(fixup_prefix, "amend")) {
+ if (use_message)
+ refname = use_message;
+ else if (!strcmp(fixup_prefix, "amend"))
+ refname = fixup_commit;
+
+ if (refname) {
struct pretty_print_context ctx = {0};
- struct commit *c = lookup_commit_reference_by_name(fixup_commit);
+ struct commit *c = lookup_commit_reference_by_name(refname);
+
if (!c)
- die(_("could not lookup commit '%s'"), fixup_commit);
+ die(_("could not lookup commit '%s'"), refname);
ctx.output_encoding = get_commit_output_encoding();
prepare_amend_commit(c, &sb, &ctx);
}
@@ -1329,9 +1337,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
}
if (fixup_message && squash_message)
die(_("options '%s' and '%s' cannot be used together"), "--squash", "--fixup");
- die_for_incompatible_opt3(!!use_message, "-C",
- !!edit_message, "-c",
- !!fixup_message, "--fixup");
die_for_incompatible_opt4(have_option_m, "-m",
!!edit_message, "-c",
!!use_message, "-C",
@@ -1396,7 +1401,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
} else {
fixup_commit = fixup_message;
fixup_prefix = "fixup";
- use_editor = 0;
+ if (!edit_message)
+ use_editor = 0;
}
}
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 9b2ecb1356..04520be0c3 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -492,6 +492,62 @@ test_expect_success 'commit --fixup works with -F' '
EOF
'
+test_expect_success 'commit --fixup works with -C' '
+ commit_for_rebase_autosquash_setup &&
+ GIT_EDITOR=false git commit --fixup HEAD~ -C HEAD &&
+ test_commit_message HEAD <<-EOF
+ fixup! $(git log -1 --format=%s HEAD~2)
+
+ $(get_commit_msg HEAD~)
+ EOF
+'
+
+test_expect_success 'commit --fixup=amend: works with -c' '
+ commit_for_rebase_autosquash_setup &&
+ GIT_EDITOR="echo edited >>" git commit --fixup=amend:HEAD -c HEAD~ &&
+ test_commit_message HEAD <<-EOF
+ amend! intermediate commit
+
+ target message subject line
+
+ target message body line 1
+ target message body line 2
+
+ edited
+ EOF
+'
+
+test_expect_success 'commit --fixup=amend:HEAD with -C HEAD and without have the same message' '
+ commit_for_rebase_autosquash_setup &&
+ start=$(git rev-parse HEAD) &&
+
+ git commit --fixup=amend:HEAD -C HEAD &&
+ git commit --fixup=amend:HEAD -C HEAD &&
+ git log -1 --pretty=%B >with-c &&
+
+ git reset --hard "$start" &&
+ git commit --fixup=amend:HEAD &&
+ git commit --fixup=amend:HEAD &&
+ git log -1 --pretty=%B >without-c &&
+
+ test_cmp with-c without-c
+'
+
+test_expect_success 'commit --fixup=amend: with -C copies full subject + body of squash commit' '
+ commit_for_rebase_autosquash_setup &&
+ git commit --squash HEAD~ -m "inner body" &&
+ echo "extra" >>foo &&
+ git add foo &&
+ git commit --fixup=amend:HEAD -C HEAD &&
+ test_commit_message HEAD <<-EOF
+ amend! squash! $(git log -1 --format=%s HEAD~3)
+
+ squash! $(git log -1 --format=%s HEAD~3)
+
+ inner body
+ EOF
+'
+
test_expect_success 'commit --fixup=reword: works with -F' '
commit_for_rebase_autosquash_setup &&
echo "message from file" >msgfile &&
@@ -553,9 +609,7 @@ test_expect_success 'invalid message options when using --fixup' '
echo changes >>foo &&
echo "message" >log &&
git add foo &&
- test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
- test_must_fail git commit --fixup HEAD~1 -c HEAD~2
+ test_must_fail git commit --fixup HEAD~1 --squash HEAD~2
'
cat >expected-template <<EOF
--
2.56.1.978.gcc9bcf3eaa
Re: [PATCH v5 1/3] commit: write the --fixup subject the way --squash does
Author: Junio C Hamano
Date: Sun, 29 Nov 2026 01:31
Date: Sun, 29 Nov 2026 01:31
72 lines
15848 bytes
15848 bytes
Erik Cervin-Edin <erik@cervined.in> writes:
> Two commits that follow teach commit --fixup how to take messages like
> --squash. In preparation for that, refactor prepare_to_commit() to
> write the --fixup subject in a block before the chain, as --squash does.
> Since the two options are mutually exclusive, put each subject block in
> its own branch of an if/else-if.
Because parse_and_validate_options() already rejects combining --fixup
and --squash with a die(), placing the fixup_message and squash_message
subject blocks in an if/else-if ahead of the message-source chain is
safe and mirrors how --squash already works.
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 36e47e18ed..698823d4fa 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -781,7 +781,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> "pre-commit", NULL))
> return 0;
>
> - if (squash_message) {
> + if (fixup_message) {
> + struct pretty_print_context ctx = {0};
> + struct commit *c;
> + char *fmt;
> + c = lookup_commit_reference_by_name(fixup_commit);
> + if (!c)
> + die(_("could not lookup commit '%s'"), fixup_commit);
> + ctx.output_encoding = get_commit_output_encoding();
> + fmt = xstrfmt("%s! %%s\n\n", fixup_prefix);
> + repo_format_commit_message(the_repository, c, fmt, &sb,
> + &ctx);
> + free(fmt);
> + if (have_option_m && !strcmp(fixup_prefix, "amend"))
> + die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> + } else if (squash_message) {
Checking the remaining arms in prepare_to_commit() confirms that
observable behavior is unchanged.
At this point in the series, -C, -c, and -F are still rejected alongside
--fixup in parse_and_validate_options(), and combining --amend with
--fixup explicitly leaves use_message NULL there.
As a result, --fixup either enters the have_option_m arm (which now sets
hook_arg1 to "message" and appends &message for plain --fixup, while
amend/reword with -m already died above) or falls through to the
fixup_message arm, which sets hook_arg1 to "message" and calls
prepare_amend_commit() for amend/reword.
> if (!strcmp(fixup_prefix, "amend")) {
> - if (have_option_m)
> - die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> - prepare_amend_commit(commit, &sb, &ctx);
> + struct pretty_print_context ctx = {0};
> + struct commit *c = lookup_commit_reference_by_name(fixup_commit);
> + if (!c)
> + die(_("could not lookup commit '%s'"), fixup_commit);
> + ctx.output_encoding = get_commit_output_encoding();
> + prepare_amend_commit(c, &sb, &ctx);
> }
> } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
> size_t merge_msg_start;
Doing a second lookup_commit_reference_by_name(fixup_commit) inside the
fixup_message arm for the amend case feels a little bit wasteful, but
keeps the subject block cleanly separated from the body block ahead of
the final patch.
Looking good.
Re: [PATCH v5 2/3] commit: allow -m/-F for all --fixup variants
Author: Junio C Hamano
Date: Sun, 29 Nov 2026 01:51
Date: Sun, 29 Nov 2026 01:51
60 lines
15405 bytes
15405 bytes
Erik Cervin-Edin <erik@cervined.in> writes:
> Allow -m and -F to supply the message body for all --fixup variants,
> mirroring the flow of a regular commit. With --fixup=amend/reword the
> given message replaces the one that would otherwise be copied from the
> target commit. Options -c and -C are handled in the next commit.
The preliminary move in [1/3] made this step a quite plesant read.
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 698823d4fa..e0fac284bc 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -793,8 +793,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> repo_format_commit_message(the_repository, c, fmt, &sb,
> &ctx);
> free(fmt);
> - if (have_option_m && !strcmp(fixup_prefix, "amend"))
> - die(_("options '%s' and '%s:%s' cannot be used together"), "-m", "--fixup", fixup_message);
> } else if (squash_message) {
> /*
> * Insert the proper subject line before other commit
> @@ -1331,9 +1329,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
> }
> if (fixup_message && squash_message)
> die(_("options '%s' and '%s' cannot be used together"), "--squash", "--fixup");
> - die_for_incompatible_opt4(!!use_message, "-C",
> + die_for_incompatible_opt3(!!use_message, "-C",
> !!edit_message, "-c",
> - !!logfile, "-F",
> !!fixup_message, "--fixup");
> die_for_incompatible_opt4(have_option_m, "-m",
> !!edit_message, "-c",
Covering all the possible interactions that can conflict and validating
that coverage is tricky. I tried to walk through the code flow but I am
not convinced myself, so let me think aloud.
Because logfile and have_option_m still clear use_editor early in
parse_and_validate_options() and free template_file, neither
commit.template nor an unintended editor session can interfere, while an
explicit -e/--edit still overrides use_editor via edit_flag as it does
for regular commits. For --fixup=amend: and --fixup=reword:,
cmd_commit() checks message_is_empty() past commit_subject_length()
whenever the message starts with "amend! ", so an empty -m or -F body
still aborts unless --allow-empty-message is passed.
> @@ -526,8 +555,7 @@ test_expect_success 'invalid message options when using --fixup' '
> git add foo &&
> test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
> test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
> - test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
> - test_must_fail git commit --fixup HEAD~1 -F log
> + test_must_fail git commit --fixup HEAD~1 -c HEAD~2
> '
We lost "-F log" check, so the 'echo' before the precontext of this hunk
that sets up the contents of the log file can and should be removed,
too.
Re: [PATCH v5 3/3] commit: allow -c/-C for all --fixup variants
Author: Junio C Hamano
Date: Sun, 29 Nov 2026 18:34
Date: Sun, 29 Nov 2026 18:34
35 lines
13570 bytes
13570 bytes
Erik Cervin-Edin <erik@cervined.in> writes:
> Plain --fixup turns the editor off. Keep it on when using -c, so that
> -c isn't silently treated like -C.
I believe that this matches what Phillip suggested us doing, and I agree
that would be a desirable behaviour.
I however do not see this combination of --fixup and -c covered in new
tests in t7500. Should we have one, or is it too trivial?
> Helped-by: Junio C Hamano <gitster@pobox.com>
I do not think I deserve this line as much as others would.
> Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
> @@ -1396,7 +1401,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
> } else {
> fixup_commit = fixup_message;
> fixup_prefix = "fixup";
> - use_editor = 0;
> + if (!edit_message)
> + use_editor = 0;
> }
> }
Tricky but true. Naively if you do not have a message you would think
you want to use editor to give the user a chance to supply one, but that
is not how this part of the world works. It might deserve a short
in-code comment why disabling of use_editor is done here and only when
!edit_message to help future readers. I dunno.
Thanks.
Re: [PATCH v5 3/3] commit: allow -c/-C for all --fixup variants
Author: Phillip Wood
Date: Mon, 30 Nov 2026 14:28
Date: Mon, 30 Nov 2026 14:28
44 lines
12377 bytes
12377 bytes
On 29/11/2026 18:34, Junio C Hamano wrote:
> Erik Cervin-Edin <erik@cervined.in> writes:
>
>> Plain --fixup turns the editor off. Keep it on when using -c, so that
>> -c isn't silently treated like -C.
>
> I believe that this matches what Phillip suggested us doing, and I agree
> that would be a desirable behaviour.
>
> I however do not see this combination of --fixup and -c covered in new
> tests in t7500. Should we have one, or is it too trivial?
It would be nice, but I'm not sure it is essential, it seems a pretty
obscure combination of options.
Thanks
Phillip
>
>> Helped-by: Junio C Hamano <gitster@pobox.com>
>
> I do not think I deserve this line as much as others would.
>
>> Signed-off-by: Erik Cervin-Edin <erik@cervined.in>
>
>> @@ -1396,7 +1401,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
>> } else {
>> fixup_commit = fixup_message;
>> fixup_prefix = "fixup";
>> - use_editor = 0;
>> + if (!edit_message)
>> + use_editor = 0;
>> }
>> }
>
> Tricky but true. Naively if you do not have a message you would think
> you want to use editor to give the user a chance to supply one, but that
> is not how this part of the world works. It might deserve a short
> in-code comment why disabling of use_editor is done here and only when
> !edit_message to help future readers. I dunno.
>
> Thanks.
Re: [PATCH v5 0/3] commit: allow -m/-F/-c/-C for all --fixup variants
Author: Phillip Wood
Date: Mon, 30 Nov 2026 14:29
Date: Mon, 30 Nov 2026 14:29
88 lines
14805 bytes
14805 bytes
Hi Erik
On 28/11/2026 12:13, Erik Cervin-Edin wrote:
> Changes since v4:
>
> * 3/3: plain --fixup -c now opens the editor, as -c does everywhere
> else. v4 kept plain --fixup's existing no-editor behavior, which
> meant -c silently acted like -C.
This looks as I expected, I don't have anything to add to Junio's comments.
Thanks for working on it
Phillip
> Background
> ----------
>
> Today only -m works with plain --fixup, and neither -m nor -F works
> with --fixup=amend: or --fixup=reword:, which makes those modes
> awkward to drive non-interactively.
>
> * 1/3 is a preparatory refactor that writes the --fixup subject before
> choosing the message source, like --squash does.
>
> * 2/3 lets -m and -F supply the message for all --fixup variants.
>
> * 3/3 does the same for -c/-C, so that all four message sources behave
> consistently across the plain, amend, and reword forms.
>
> As in v3 and v4, -c/-C go through prepare_amend_commit(), so if
> the source commit is itself an "amend!" commit, its subject line is
> dropped and only the body is copied. This is what a no-source
> --fixup=amend:<commit> already does. The helper only knows about
> "amend!" and not "fixup!" or "squash!"; that is pre-existing and I have
> left it alone here.
>
> The earlier rounds are described in the v2 [1], v3 [2] and v4 [3]
> cover letters.
>
> [1] https://lore.kernel.org/git/cover.1779792311.git.erik@cervined.in/
> [2] https://lore.kernel.org/git/cover.1790082176.git.erik@cervined.in/
> [3] https://lore.kernel.org/git/cover.1795562078.git.erik@cervined.in/
>
> Erik Cervin-Edin (3):
> commit: write the --fixup subject the way --squash does
> commit: allow -m/-F for all --fixup variants
> commit: allow -c/-C for all --fixup variants
>
> Documentation/git-commit.adoc | 22 +++--
> builtin/commit.c | 64 ++++++------
> t/t7500-commit-template-squash-signoff.sh | 114 +++++++++++++++++++---
> 3 files changed, 140 insertions(+), 60 deletions(-)
>
> Range-diff against v4:
> 1: ebae1fbe05 = 1: ebae1fbe05 commit: write the --fixup subject the way --squash does
> 2: 051b659965 = 2: 051b659965 commit: allow -m/-F for all --fixup variants
> 3: 159a56c510 ! 3: 9ab3665cfc commit: allow -c/-C for all --fixup variants
> @@ Commit message
> autosquash. This also means that "git commit --fixup=amend:X -C X"
> produces the same message as "GIT_EDITOR=: git commit --fixup=amend:X".
>
> - Plain --fixup never opens an editor, so -c there behaves like -C.
> + Plain --fixup turns the editor off. Keep it on when using -c, so that
> + -c isn't silently treated like -C.
>
> The incompatibility check grouping -C, -c, and --fixup can go away
> entirely, as -C and -c are already rejected together by the check that
> @@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *ar
> die_for_incompatible_opt4(have_option_m, "-m",
> !!edit_message, "-c",
> !!use_message, "-C",
> +@@ builtin/commit.c: static int parse_and_validate_options(int argc, const char *argv[],
> + } else {
> + fixup_commit = fixup_message;
> + fixup_prefix = "fixup";
> +- use_editor = 0;
> ++ if (!edit_message)
> ++ use_editor = 0;
> + }
> + }
> +
>
> ## t/t7500-commit-template-squash-signoff.sh ##
> @@ t/t7500-commit-template-squash-signoff.sh: test_expect_success 'commit --fixup works with -F' '
>
> base-commit: f7de81456940dd6f3274e461149bba12965de609
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads