Volume XXII, number 279Tuesday, October 6, 2026Latest message 38 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

RFC patch, 2 partsbuiltin/history: change git history reword behavior and feedback

36 messages between Jun 7, 2026 and Jul 8, 2026, from Pablo Sabater, Patrick Steinhardt, Junio C Hamano, Ben Knoble, Kristoffer Haugsbakk, Phillip Wood, Justin Tobler, Dominique Martinet, D. Ben Knoble.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Pablo SabaterJun 7, 2026, 20:07 UTC on lore
This small series contains two commits that aim to improve
`git history reword`:
1. Abort the reword when the original message and the new message are
   the same to avoid unnecessary history changes.
2. Print feedback after a successful reword so the user knows about it.
`git commit --amend` and `git rebase -i` with reword don't abort if
the commit message is the same as the original and they update as if
it was a new message in favor of changing this behavior for
`git history reword`:
- As noted in the `git history` documentation, the command by
  default updates all branches that contain the original commit [1]
  this makes `git history reword` more expensive than other options
  like `git rebase -i` that only updates the current branch.
- `git history` works in-memory without touching the worktree or index
  [2], because it doesn't use the sequencer and `git history reword`
  doesn't care about the staged files only about the commit message, it
  should have no problems.

About the last fact in favor of 1, I'm not completely sure if it's because of staged files that's the reason why `git commit --amend` or `git rebase -i` with reword still updates even if the commit message is the same one. I'm not very up to sequencer.c to be sure but maybe there's a historical reason about it that someone knows. Anyways I believe that given this new command is a good idea to discuss it.

The commit message of 1 mentions staged files as a possible justification for why --amend and rebase behave this way, but that's just an assumption that I'll be happy to change if I'm wrong.

[1]: https://git-scm.com/docs/git-history#_description [2]: https://lore.kernel.org/git/20260113-b4-pks-history-builtin-v11-8-e74ebfa2652d@pks.im/

To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>
Cc: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
Pablo Sabater (2):
      builtin/history: abort reword on unchanged message
      builtin/history: print feedback after successful reword
 builtin/history.c         | 14 ++++++++++++++
 t/t3451-history-reword.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
---
base-commit: 9ac3f193c05c2237e2b14ebaa1149e9fc8a1abe0
change-id: 20260607-ps-history-reword-fcb70eaa4aa9

Best regards, -- Pablo Sabater <pabloosabaterr@gmail.com>

Pablo SabaterJun 7, 2026, 20:07 UTC in reply to Pablo Sabater on lore

[PATCH RFC 1/2] builtin/history: abort reword on unchanged message

When using `git history reword` if the new message is the same as the original it continues anyway creating a new commit with the same message and updates its descendants, modifying the history after this 'reworded' commit even though there was no actual change.

`git commit --amend` and `git rebase -i` + reword share this behavior,
however `git history reword` is different:
1. Works in-memory without touching the index or the worktree [1], so
   there are no side effects like staged files that could justify
   rewriting the history when the commit message is the same.
2. `git history` by default updates all the branches [2] that contain the
   original commit making it more costly than `git rebase -i` that only
   updates the current branch.

Add a check if the original commit message is the same as the new one and abort if so.

[1]: https://lore.kernel.org/git/20260113-b4-pks-history-builtin-v11-8-e74ebfa2652d@pks.im/ [2]: https://git-scm.com/docs/git-history#_description

Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
 builtin/history.c         | 10 ++++++++++
 t/t3451-history-reword.sh | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+)
Show changes to 2 files +30 −0

builtin/history.c, t/t3451-history-reword.sh

diff --git a/builtin/history.c b/builtin/history.c
index 0fc06fb204..51a22a9a1c 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -135,6 +135,13 @@ static int commit_tree_ext(struct repository *repo,
 					  original_body, action, &commit_message);
 		if (ret < 0)
 			goto out;
+
+		if (!strcmp(original_body, commit_message.buf)) {
+			fprintf(stderr, _("Message unchanged,"
+					  " aborting reword.\n"));
+			ret = 1;
+			goto out;
+		}
 	} else {
 		strbuf_addstr(&commit_message, original_body);
 	}
@@ -718,6 +725,9 @@ static int cmd_history_reword(int argc,
 	if (ret < 0) {
 		ret = error(_("failed writing reworded commit"));
 		goto out;
+	} else if (ret == 1) {
+		ret = 0;
+		goto out;
 	}
 
 	strbuf_addf(&reflog_msg, "reword: updating %s", argv[0]);
diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
index de7b357685..54ea8a7207 100755
--- a/t/t3451-history-reword.sh
+++ b/t/t3451-history-reword.sh
@@ -396,4 +396,24 @@ test_expect_success 'retains changes in the worktree and index' '
 	)
 '
 
+test_expect_success 'aborts if the commit message is the same' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit first &&
+		test_commit second &&
+
+		git rev-parse HEAD >oid-before &&
+		write_script fake-editor.sh <<-\EOF &&
+		true
+		EOF
+		test_set_editor "$(pwd)"/fake-editor.sh &&
+		git history reword HEAD 2>err &&
+		git rev-parse HEAD >oid-after &&
+		test_cmp oid-before oid-after &&
+		test_grep "Message unchanged" err
+	)
+'
+
 test_done
-- 
2.54.0
Pablo SabaterJun 7, 2026, 20:07 UTC in reply to Pablo Sabater on lore

[PATCH RFC 2/2] builtin/history: print feedback after successful reword

Unlike `git commit --amend` and `git rebase -i`, `git history reword` doesn't print anything, this makes it feel empty for a porcelain command and hard to tell if the command did anything without using other commands like `git log <commit>` to check if the reword was done.

Print a message on successful rewords so the user has feedback about it.
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
 builtin/history.c         |  4 ++++
 t/t3451-history-reword.sh | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
Show changes to 2 files +18 −0

builtin/history.c, t/t3451-history-reword.sh

diff --git a/builtin/history.c b/builtin/history.c
index 51a22a9a1c..0f1ba3b531 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -739,6 +739,10 @@ static int cmd_history_reword(int argc,
 		goto out;
 	}
 
+	fprintf(stderr, _("Successfully reworded commit %s to %s\n"),
+		repo_find_unique_abbrev(repo, &original->object.oid, DEFAULT_ABBREV),
+		repo_find_unique_abbrev(repo, &rewritten->object.oid, DEFAULT_ABBREV));
+
 	ret = 0;
 
 out:
diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
index 54ea8a7207..4b22d761e3 100755
--- a/t/t3451-history-reword.sh
+++ b/t/t3451-history-reword.sh
@@ -416,4 +416,18 @@ test_expect_success 'aborts if the commit message is the same' '
 	)
 '
 
+test_expect_success 'prints feedback on successful reword' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit first &&
+
+		reword_with_message HEAD 2>err <<-EOF &&
+		first reworded
+		EOF
+		test_grep "Successfully reworded" err
+	)
+'
+
 test_done
-- 
2.54.0
Patrick SteinhardtJun 8, 2026, 09:30 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

On Sun, Jun 07, 2026 at 10:07:20PM +0200, Pablo Sabater wrote:
Show 19 quoted lines
> When using `git history reword` if the new message is the same as the
> original it continues anyway creating a new commit with the same
> message and updates its descendants, modifying the history after this
> 'reworded' commit even though there was no actual change.
> 
> `git commit --amend` and `git rebase -i` + reword share this behavior,
> however `git history reword` is different:
> 1. Works in-memory without touching the index or the worktree [1], so
>    there are no side effects like staged files that could justify
>    rewriting the history when the commit message is the same.
> 2. `git history` by default updates all the branches [2] that contain the
>    original commit making it more costly than `git rebase -i` that only
>    updates the current branch.
> 
> Add a check if the original commit message is the same as the new one
> and abort if so.
> 
> [1]: https://lore.kernel.org/git/20260113-b4-pks-history-builtin-v11-8-e74ebfa2652d@pks.im/
> [2]: https://git-scm.com/docs/git-history#_description
Nit: I feel like both of the links don't really add much value.
Show 24 quoted lines
> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> ---
>  builtin/history.c         | 10 ++++++++++
>  t/t3451-history-reword.sh | 20 ++++++++++++++++++++
>  2 files changed, 30 insertions(+)
> 
> diff --git a/builtin/history.c b/builtin/history.c
> index 0fc06fb204..51a22a9a1c 100644
> --- a/builtin/history.c
> +++ b/builtin/history.c
> @@ -135,6 +135,13 @@ static int commit_tree_ext(struct repository *repo,
>  					  original_body, action, &commit_message);
>  		if (ret < 0)
>  			goto out;
> +
> +		if (!strcmp(original_body, commit_message.buf)) {
> +			fprintf(stderr, _("Message unchanged,"
> +					  " aborting reword.\n"));
> +			ret = 1;
> +			goto out;
> +		}
>  	} else {
>  		strbuf_addstr(&commit_message, original_body);
>  	}

We also execute this logic via "git history fixup --reedit-message", and here it wouldn't make sense to abort the commit in case the message is unchanged.

Patrick
Patrick SteinhardtJun 8, 2026, 09:30 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

On Sun, Jun 07, 2026 at 10:07:21PM +0200, Pablo Sabater wrote:
Show 6 quoted lines
> Unlike `git commit --amend` and `git rebase -i`, `git history reword`
> doesn't print anything, this makes it feel empty for a porcelain command
> and hard to tell if the command did anything without using other
> commands like `git log <commit>` to check if the reword was done.
> 
> Print a message on successful rewords so the user has feedback about it.

I dunno about this one. My take here is that a command should be silent unless it has something to say, for example when it couldn't honor the user's request [1].

Show 12 quoted lines
> diff --git a/builtin/history.c b/builtin/history.c
> index 51a22a9a1c..0f1ba3b531 100644
> --- a/builtin/history.c
> +++ b/builtin/history.c
> @@ -739,6 +739,10 @@ static int cmd_history_reword(int argc,
>  		goto out;
>  	}
>  
> +	fprintf(stderr, _("Successfully reworded commit %s to %s\n"),
> +		repo_find_unique_abbrev(repo, &original->object.oid, DEFAULT_ABBREV),
> +		repo_find_unique_abbrev(repo, &rewritten->object.oid, DEFAULT_ABBREV));
> +
Seeing the implementation also raises a couple of questions:
  - Why do we mention the rewritten commit, only? Shouldn't we also
    print the changed HEAD?
  - Why don't we print any of the other rewritten branches?
  - What makes "git history reword" so special as compared to for
    example "git history fixup" or "git history split" so that it needs
    a message while the others don't?

It might make sense to maybe introduce a verbose mode where we do print such information. But if so, we should have good answers to the above questions and implement this in a way that makes sense for the other subcommands, too, so that we can apply the same principle to all of them.

Thanks!
Patrick
[1]: https://www.linfo.org/rule_of_silence.html
Pablo SabaterJun 8, 2026, 10:45 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

El lun, 8 jun 2026 a las 11:30, Patrick Steinhardt (<ps@pks.im>) escribió:
Show 12 quoted lines
>
> On Sun, Jun 07, 2026 at 10:07:21PM +0200, Pablo Sabater wrote:
> > Unlike `git commit --amend` and `git rebase -i`, `git history reword`
> > doesn't print anything, this makes it feel empty for a porcelain command
> > and hard to tell if the command did anything without using other
> > commands like `git log <commit>` to check if the reword was done.
> >
> > Print a message on successful rewords so the user has feedback about it.
>
> I dunno about this one. My take here is that a command should be silent
> unless it has something to say, for example when it couldn't honor the
> user's request [1].

But neither `git commit --amend` nor `git rebase -i` follow this rule of silence.

Show 18 quoted lines
>
> > diff --git a/builtin/history.c b/builtin/history.c
> > index 51a22a9a1c..0f1ba3b531 100644
> > --- a/builtin/history.c
> > +++ b/builtin/history.c
> > @@ -739,6 +739,10 @@ static int cmd_history_reword(int argc,
> >               goto out;
> >       }
> >
> > +     fprintf(stderr, _("Successfully reworded commit %s to %s\n"),
> > +             repo_find_unique_abbrev(repo, &original->object.oid, DEFAULT_ABBREV),
> > +             repo_find_unique_abbrev(repo, &rewritten->object.oid, DEFAULT_ABBREV));
> > +
>
> Seeing the implementation also raises a couple of questions:
>
>   - Why do we mention the rewritten commit, only? Shouldn't we also
>     print the changed HEAD?

Because `git history reword <commit>` is for a single commit. After the reword the hash changes and the original hash is no longer useful to check the rewritten message. If I want to see how it is now:

  $ git history reword aabb
  $ git log aabb <- I can't check how it is now because this is the old one

So to check the new one I have to search the new hash. Imagine if it's the first of 20 long commit messages, I have to git log --oneline, get the hash and then git log new_hash, which IMO is unnecessary when git history reword can output the new hash.

>
>   - Why don't we print any of the other rewritten branches?

Haven't thought of that, it's nice that it does modify all branches, I just assumed that the most relevant is the current branch new commit hash. The other rewritten branches have the same commit message, just different hashes.

>
>   - What makes "git history reword" so special as compared to for
>     example "git history fixup" or "git history split" so that it needs
>     a message while the others don't?

Nothing, I just wanted this specifically for reword and sent this very simple as an RFC to discuss the idea, I could extend this where it fits.

Show 6 quoted lines
>
> It might make sense to maybe introduce a verbose mode where we do print
> such information. But if so, we should have good answers to the above
> questions and implement this in a way that makes sense for the other
> subcommands, too, so that we can apply the same principle to all of
> them.

I like the verbose mode idea but I still think that on non-verbose something should be printed, on verbose it could be printed additionally all the rewritten commits (though it could get very noisy), the changed HEAD, etc.

Show 6 quoted lines
>
> Thanks!
>
> Patrick
>
> [1]: https://www.linfo.org/rule_of_silence.html

-- Pablo

Pablo SabaterJun 8, 2026, 10:52 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

El lun, 8 jun 2026 a las 11:30, Patrick Steinhardt (<ps@pks.im>) escribió:
Show 23 quoted lines
>
> On Sun, Jun 07, 2026 at 10:07:20PM +0200, Pablo Sabater wrote:
> > When using `git history reword` if the new message is the same as the
> > original it continues anyway creating a new commit with the same
> > message and updates its descendants, modifying the history after this
> > 'reworded' commit even though there was no actual change.
> >
> > `git commit --amend` and `git rebase -i` + reword share this behavior,
> > however `git history reword` is different:
> > 1. Works in-memory without touching the index or the worktree [1], so
> >    there are no side effects like staged files that could justify
> >    rewriting the history when the commit message is the same.
> > 2. `git history` by default updates all the branches [2] that contain the
> >    original commit making it more costly than `git rebase -i` that only
> >    updates the current branch.
> >
> > Add a check if the original commit message is the same as the new one
> > and abort if so.
> >
> > [1]: https://lore.kernel.org/git/20260113-b4-pks-history-builtin-v11-8-e74ebfa2652d@pks.im/
> > [2]: https://git-scm.com/docs/git-history#_description
>
> Nit: I feel like both of the links don't really add much value.
I'll just drop em.
Show 29 quoted lines
>
> > Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> > ---
> >  builtin/history.c         | 10 ++++++++++
> >  t/t3451-history-reword.sh | 20 ++++++++++++++++++++
> >  2 files changed, 30 insertions(+)
> >
> > diff --git a/builtin/history.c b/builtin/history.c
> > index 0fc06fb204..51a22a9a1c 100644
> > --- a/builtin/history.c
> > +++ b/builtin/history.c
> > @@ -135,6 +135,13 @@ static int commit_tree_ext(struct repository *repo,
> >                                         original_body, action, &commit_message);
> >               if (ret < 0)
> >                       goto out;
> > +
> > +             if (!strcmp(original_body, commit_message.buf)) {
> > +                     fprintf(stderr, _("Message unchanged,"
> > +                                       " aborting reword.\n"));
> > +                     ret = 1;
> > +                     goto out;
> > +             }
> >       } else {
> >               strbuf_addstr(&commit_message, original_body);
> >       }
>
> We also execute this logic via "git history fixup --reedit-message", and
> here it wouldn't make sense to abort the commit in case the message is
> unchanged.

True I hadn't thought that, I made it here because we have both the original and new message before creating the new commit. We could let ret = 1 mean that the commit message is the same and then cmd_history_fixup ignores ret = 1 and for cmd_history_reword handle the abort. What do you think?

>
> Patrick

-- Pablo

Junio C HamanoJun 8, 2026, 12:16 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

Pablo Sabater <pabloosabaterr@gmail.com> writes:
Show 28 quoted lines
> Unlike `git commit --amend` and `git rebase -i`, `git history reword`
> doesn't print anything, this makes it feel empty for a porcelain command
> and hard to tell if the command did anything without using other
> commands like `git log <commit>` to check if the reword was done.
>
> Print a message on successful rewords so the user has feedback about it.
>
> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> ---
>  builtin/history.c         |  4 ++++
>  t/t3451-history-reword.sh | 14 ++++++++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/builtin/history.c b/builtin/history.c
> index 51a22a9a1c..0f1ba3b531 100644
> --- a/builtin/history.c
> +++ b/builtin/history.c
> @@ -739,6 +739,10 @@ static int cmd_history_reword(int argc,
>  		goto out;
>  	}
>  
> +	fprintf(stderr, _("Successfully reworded commit %s to %s\n"),
> +		repo_find_unique_abbrev(repo, &original->object.oid, DEFAULT_ABBREV),
> +		repo_find_unique_abbrev(repo, &rewritten->object.oid, DEFAULT_ABBREV));
> +
>  	ret = 0;
>  
>  out:

Do other commands in "git history" (split is in 'master', drop and fixup are cooking) behave with similar verbosity? Consistency within the same "history" umbrella matters more than being similar with other commands that can be used for similar purposes.

Show 23 quoted lines
> diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
> index 54ea8a7207..4b22d761e3 100755
> --- a/t/t3451-history-reword.sh
> +++ b/t/t3451-history-reword.sh
> @@ -416,4 +416,18 @@ test_expect_success 'aborts if the commit message is the same' '
>  	)
>  '
>  
> +test_expect_success 'prints feedback on successful reword' '
> +	test_when_finished "rm -rf repo" &&
> +	git init repo &&
> +	(
> +		cd repo &&
> +		test_commit first &&
> +
> +		reword_with_message HEAD 2>err <<-EOF &&
> +		first reworded
> +		EOF
> +		test_grep "Successfully reworded" err
> +	)
> +'
> +
>  test_done
Junio C HamanoJun 8, 2026, 12:16 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

Pablo Sabater <pabloosabaterr@gmail.com> writes:
Show 13 quoted lines
> When using `git history reword` if the new message is the same as the
> original it continues anyway creating a new commit with the same
> message and updates its descendants, modifying the history after this
> 'reworded' commit even though there was no actual change.
>
> `git commit --amend` and `git rebase -i` + reword share this behavior,
> however `git history reword` is different:
> 1. Works in-memory without touching the index or the worktree [1], so
>    there are no side effects like staged files that could justify
>    rewriting the history when the commit message is the same.
> 2. `git history` by default updates all the branches [2] that contain the
>    original commit making it more costly than `git rebase -i` that only
>    updates the current branch.
I think the reasoning is flawed.

Both "git commit --amend" and "git rebase -i", even with no changes to the tree, parents, or the message, update the committer timestamp (and perhaps the committer identity running the command may be different from the original). Updating this info is one of the important effects of the command.

And "history" being more capable than "rebase" is a wrong excuse to make the system behave inconsistently between commands that have similar features [*1*]. In a situation where letting 'history' update all the relevant branches, if a command behaves differently from the way the user likes (and if the way 'rebase -i' works is the one the user likes), you'd end up forcing the user to use 'rebase -i' when 'history' would have been more appropriate.

Having said that, I personally think that the current behaviour of `commit --amend` and `history reword` are both _wrong_ [*2*].

You may start `git commit --amend`, and after staring at the existing commit log message for some time in your editor, it is quite natural for you to decide that leaving the commit as-is is the right thing [*3*] in your situation. It may have been a better design for the system to notice this situation and leave the commit as-is, with an override option `--force` to allow users to forcibly update the committer ident and timestamp in the commit header. I am not a `history reword` user (yet), but from the motivation you described for this patch, I sense that the story is the same there.

`git rebase -i A`, when A is truly an ancestor at the bottom of a linear history leading to HEAD, behaves slightly better. It gives you a todo list with a bunch of `pick` insns, and when you do not edit earliest 'pick's the todo list, these earliest commits are left as-is. It may still share the same issue that a 'reword' that you ended up not rewording (or 'edit' that you ended up not touching its tree or log message) does still recreate a new commit object, though.

`git rebase -i` may have an excuse that because it, unlike "git commit --amend", operates on multiple commits by design. A single "--force" option given to the command would not have worked as an escape hatch to allow the user to tell the command "in this reword of this particular commit, I ended up doing nothing, but I still want an updated committer log timestamp". Perhaps giving the "--force" (or --force-rewrite") option at "rebase --continue" time may work, but in any case, unless we plan to transition to these "better" default behaviour at a big version boundary, speculating what a "better" behaviour would have been may be fun but not very productive.

[Footnote]
 *1* Besides, doesn't "--update-refs" in "rebase -i" allow you to
     adjust the branches?
 *2* But it is an established behaviour people _rely_ on, so even
     though it may have been better if these commands behaved
     differently, it probably is a bit too late to change it now.
 *3* This includes the case where the original author is especially
     difficult to work with and would complain any change to their
     commits, even if the only change you made for them is a
     typofix.  Fixing a small typo/grammo may not be worth your time
     and unpleasant exchanges with them after touching their commit.
Pablo SabaterJun 8, 2026, 13:23 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

El lun, 8 jun 2026 a las 14:16, Junio C Hamano (<gitster@pobox.com>) escribió:
Show 36 quoted lines
>
> Pablo Sabater <pabloosabaterr@gmail.com> writes:
>
> > Unlike `git commit --amend` and `git rebase -i`, `git history reword`
> > doesn't print anything, this makes it feel empty for a porcelain command
> > and hard to tell if the command did anything without using other
> > commands like `git log <commit>` to check if the reword was done.
> >
> > Print a message on successful rewords so the user has feedback about it.
> >
> > Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> > ---
> >  builtin/history.c         |  4 ++++
> >  t/t3451-history-reword.sh | 14 ++++++++++++++
> >  2 files changed, 18 insertions(+)
> >
> > diff --git a/builtin/history.c b/builtin/history.c
> > index 51a22a9a1c..0f1ba3b531 100644
> > --- a/builtin/history.c
> > +++ b/builtin/history.c
> > @@ -739,6 +739,10 @@ static int cmd_history_reword(int argc,
> >               goto out;
> >       }
> >
> > +     fprintf(stderr, _("Successfully reworded commit %s to %s\n"),
> > +             repo_find_unique_abbrev(repo, &original->object.oid, DEFAULT_ABBREV),
> > +             repo_find_unique_abbrev(repo, &rewritten->object.oid, DEFAULT_ABBREV));
> > +
> >       ret = 0;
> >
> >  out:
>
> Do other commands in "git history" (split is in 'master', drop and
> fixup are cooking) behave with similar verbosity?  Consistency within
> the same "history" umbrella matters more than being similar with
> other commands that can be used for similar purposes.

They do not, they are thought with the rule of silence in mind. However I think that this output is valuable information I might have explained myself better at [1] but my thought is:

git history reword aabb

Now that I have my commit aabb rewritten I want to check it again just to make sure I did what I wanted correctly, but git log aabb is still the old commit, the rewritten one has a different hash which I do not know unless I search for it, if it's far from HEAD I'd have to git log --oneline, get the hash and then git log new_hash. I think that git history reword that does have the information about the new hash should print it to avoid this search. What I want is something like:

git history reword aabb Successfully reworded aabb to ccdd

So I can just git log ccdd without having to search.

I want to say I haven't looked as much as I'd like to split, drop and fixup, but I think it would be a good addition for them also. On [1] Patrick wrote about a --verbose for git history, I think that the basic information i.e. at reword which is the new hash should be always printed but if it's preferred it could go there.

For split it can print the hashes of the new commits like: "...split into ccdd and eeff." For fixup the commit hash also changes, so the same as reword. The one that will have more friction would be drop is the one that doesn't end up with new commits.

[1]: https://lore.kernel.org/git/CAN5EUNSAOMRvmLGVfzQiwWoOn9VGNVU5rVMZizOryn_q2fbCNA@mail.gmail.com/
Show 24 quoted lines
>
> > diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
> > index 54ea8a7207..4b22d761e3 100755
> > --- a/t/t3451-history-reword.sh
> > +++ b/t/t3451-history-reword.sh
> > @@ -416,4 +416,18 @@ test_expect_success 'aborts if the commit message is the same' '
> >       )
> >  '
> >
> > +test_expect_success 'prints feedback on successful reword' '
> > +     test_when_finished "rm -rf repo" &&
> > +     git init repo &&
> > +     (
> > +             cd repo &&
> > +             test_commit first &&
> > +
> > +             reword_with_message HEAD 2>err <<-EOF &&
> > +             first reworded
> > +             EOF
> > +             test_grep "Successfully reworded" err
> > +     )
> > +'
> > +
> >  test_done
Ben KnobleJun 8, 2026, 16:37 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

I don’t have any strong opinions on the rest…
Show 82 quoted lines
> Le 7 juin 2026 à 16:08, Pablo Sabater <pabloosabaterr@gmail.com> a écrit :
> 
> When using `git history reword` if the new message is the same as the
> original it continues anyway creating a new commit with the same
> message and updates its descendants, modifying the history after this
> 'reworded' commit even though there was no actual change.
> 
> `git commit --amend` and `git rebase -i` + reword share this behavior,
> however `git history reword` is different:
> 1. Works in-memory without touching the index or the worktree [1], so
>   there are no side effects like staged files that could justify
>   rewriting the history when the commit message is the same.
> 2. `git history` by default updates all the branches [2] that contain the
>   original commit making it more costly than `git rebase -i` that only
>   updates the current branch.
> 
> Add a check if the original commit message is the same as the new one
> and abort if so.
> 
> [1]: https://lore.kernel.org/git/20260113-b4-pks-history-builtin-v11-8-e74ebfa2652d@pks.im/
> [2]: https://git-scm.com/docs/git-history#_description
> 
> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> ---
> builtin/history.c         | 10 ++++++++++
> t/t3451-history-reword.sh | 20 ++++++++++++++++++++
> 2 files changed, 30 insertions(+)
> 
> diff --git a/builtin/history.c b/builtin/history.c
> index 0fc06fb204..51a22a9a1c 100644
> --- a/builtin/history.c
> +++ b/builtin/history.c
> @@ -135,6 +135,13 @@ static int commit_tree_ext(struct repository *repo,
>                      original_body, action, &commit_message);
>        if (ret < 0)
>            goto out;
> +
> +        if (!strcmp(original_body, commit_message.buf)) {
> +            fprintf(stderr, _("Message unchanged,"
> +                      " aborting reword.\n"));
> +            ret = 1;
> +            goto out;
> +        }
>    } else {
>        strbuf_addstr(&commit_message, original_body);
>    }
> @@ -718,6 +725,9 @@ static int cmd_history_reword(int argc,
>    if (ret < 0) {
>        ret = error(_("failed writing reworded commit"));
>        goto out;
> +    } else if (ret == 1) {
> +        ret = 0;
> +        goto out;
>    }
> 
>    strbuf_addf(&reflog_msg, "reword: updating %s", argv[0]);
> diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
> index de7b357685..54ea8a7207 100755
> --- a/t/t3451-history-reword.sh
> +++ b/t/t3451-history-reword.sh
> @@ -396,4 +396,24 @@ test_expect_success 'retains changes in the worktree and index' '
>    )
> '
> 
> +test_expect_success 'aborts if the commit message is the same' '
> +    test_when_finished "rm -rf repo" &&
> +    git init repo &&
> +    (
> +        cd repo &&
> +        test_commit first &&
> +        test_commit second &&
> +
> +        git rev-parse HEAD >oid-before &&
> +        write_script fake-editor.sh <<-\EOF &&
> +        true
> +        EOF
> +        test_set_editor "$(pwd)"/fake-editor.sh &&
> +        git history reword HEAD 2>err &&
> +        git rev-parse HEAD >oid-after &&
> +        test_cmp oid-before oid-after &&
> +        test_grep "Message unchanged" err
> +    )
…but I think this test case could do something like "GIT_EDITOR=true git history reword HEAD" and avoid the script?
Show 6 quoted lines
> +'
> +
> test_done
> 
> --
> 2.54.0

Best, Ben

Ben KnobleJun 8, 2026, 16:44 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

> Le 8 juin 2026 à 08:23, Junio C Hamano <gitster@pobox.com> a écrit :
> 
[snip]
Show 12 quoted lines
> Having said that, I personally think that the current behaviour of
> `commit --amend` and `history reword` are both _wrong_ [*2*].
> 
> You may start `git commit --amend`, and after staring at the
> existing commit log message for some time in your editor, it is
> quite natural for you to decide that leaving the commit as-is is the
> right thing [*3*] in your situation.  It may have been a better
> design for the system to notice this situation and leave the commit
> as-is, with an override option `--force` to allow users to forcibly
> update the committer ident and timestamp in the commit header.  I am
> not a `history reword` user (yet), but from the motivation you
> described for this patch, I sense that the story is the same there.
FWIW, in this situation I abort my editor (:cquit in Vim) so that the amend gets an error-valued exit code from the subprocess and aborts itself. 
Perhaps there could/should be a better side-channel for communicating that, though? I do not know how easy it is to tell other editors to « quit with errors ».
Show 14 quoted lines
> [Footnote]
> 
> *1* Besides, doesn't "--update-refs" in "rebase -i" allow you to
>     adjust the branches?
> 
> *2* But it is an established behaviour people _rely_ on, so even
>     though it may have been better if these commands behaved
>     differently, it probably is a bit too late to change it now.
> 
> *3* This includes the case where the original author is especially
>     difficult to work with and would complain any change to their
>     commits, even if the only change you made for them is a
>     typofix.  Fixing a small typo/grammo may not be worth your time
>     and unpleasant exchanges with them after touching their commit.
Ben KnobleJun 8, 2026, 16:47 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

Show 48 quoted lines
> Le 8 juin 2026 à 09:29, Pablo Sabater <pabloosabaterr@gmail.com> a écrit :
> 
> El lun, 8 jun 2026 a las 14:16, Junio C Hamano (<gitster@pobox.com>) escribió:
>> 
>> Pablo Sabater <pabloosabaterr@gmail.com> writes:
>> 
>>> Unlike `git commit --amend` and `git rebase -i`, `git history reword`
>>> doesn't print anything, this makes it feel empty for a porcelain command
>>> and hard to tell if the command did anything without using other
>>> commands like `git log <commit>` to check if the reword was done.
>>> 
>>> Print a message on successful rewords so the user has feedback about it.
>>> 
>>> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
>>> ---
>>> builtin/history.c         |  4 ++++
>>> t/t3451-history-reword.sh | 14 ++++++++++++++
>>> 2 files changed, 18 insertions(+)
>>> 
>>> diff --git a/builtin/history.c b/builtin/history.c
>>> index 51a22a9a1c..0f1ba3b531 100644
>>> --- a/builtin/history.c
>>> +++ b/builtin/history.c
>>> @@ -739,6 +739,10 @@ static int cmd_history_reword(int argc,
>>>              goto out;
>>>      }
>>> 
>>> +     fprintf(stderr, _("Successfully reworded commit %s to %s\n"),
>>> +             repo_find_unique_abbrev(repo, &original->object.oid, DEFAULT_ABBREV),
>>> +             repo_find_unique_abbrev(repo, &rewritten->object.oid, DEFAULT_ABBREV));
>>> +
>>>      ret = 0;
>>> 
>>> out:
>> 
>> Do other commands in "git history" (split is in 'master', drop and
>> fixup are cooking) behave with similar verbosity?  Consistency within
>> the same "history" umbrella matters more than being similar with
>> other commands that can be used for similar purposes.
> 
> They do not, they are thought with the rule of silence in mind.
> However I think that this output is valuable information I might have
> explained myself better at [1] but my thought is:
> 
> git history reword aabb
> 
> Now that I have my commit aabb rewritten I want to check it again just
> to make sure I did what I wanted correctly,
Some thoughts:
- If the rewritten commit is an ancestor of HEAD, look at the log of HEAD@{1} or the log between HEAD and the aforementioned reflog entry. (git-range-diff may also be helpful there.)
- Similarly, if the rewritten commit is reachable from some ref R, check R@{1} etc. 
Show 26 quoted lines
> but git log aabb is still
> the old commit, the rewritten one has a different hash which I do not
> know unless I search for it, if it's far from HEAD I'd have to git log
> --oneline, get the hash and then git log new_hash. I think that git
> history reword that does have the information about the new hash
> should print it to avoid this search.
> What I want is something like:
> 
> git history reword aabb
> Successfully reworded aabb to ccdd
> 
> So I can just git log ccdd without having to search.
> 
> I want to say I haven't looked as much as I'd like to split, drop and
> fixup, but I think it would be a good addition for them also. On [1]
> Patrick wrote about a --verbose for git history, I think that the
> basic information i.e. at reword which is the new hash should be
> always printed but if it's preferred it could go there.
> 
> For split it can print the hashes of the new commits like:
> "...split into ccdd and eeff."
> For fixup the commit hash also changes, so the same as reword.
> The one that will have more friction would be drop is the one that
> doesn't end up with new commits.
> 
> [1]: https://lore.kernel.org/git/CAN5EUNSAOMRvmLGVfzQiwWoOn9VGNVU5rVMZizOryn_q2fbCNA@mail.gmail.com/
Pablo SabaterJun 9, 2026, 09:59 UTC in reply to Ben Knoble on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

El lun, 8 jun 2026 a las 18:37, Ben Knoble (<ben.knoble@gmail.com>) escribió: [snip]

Show 20 quoted lines
> > +test_expect_success 'aborts if the commit message is the same' '
> > +    test_when_finished "rm -rf repo" &&
> > +    git init repo &&
> > +    (
> > +        cd repo &&
> > +        test_commit first &&
> > +        test_commit second &&
> > +
> > +        git rev-parse HEAD >oid-before &&
> > +        write_script fake-editor.sh <<-\EOF &&
> > +        true
> > +        EOF
> > +        test_set_editor "$(pwd)"/fake-editor.sh &&
> > +        git history reword HEAD 2>err &&
> > +        git rev-parse HEAD >oid-after &&
> > +        test_cmp oid-before oid-after &&
> > +        test_grep "Message unchanged" err
> > +    )
>
> …but I think this test case could do something like "GIT_EDITOR=true git history reword HEAD" and avoid the script?
It does work, thanks.
Show 10 quoted lines
>
> > +'
> > +
> > test_done
> >
> > --
> > 2.54.0
>
> Best,
> Ben

-- Pablo

Pablo SabaterJun 9, 2026, 10:03 UTC in reply to Ben Knoble on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

El lun, 8 jun 2026 a las 18:44, Ben Knoble (<ben.knoble@gmail.com>) escribió:
Show 22 quoted lines
>
>
> > Le 8 juin 2026 à 08:23, Junio C Hamano <gitster@pobox.com> a écrit :
> >
> [snip]
>
> > Having said that, I personally think that the current behaviour of
> > `commit --amend` and `history reword` are both _wrong_ [*2*].
> >
> > You may start `git commit --amend`, and after staring at the
> > existing commit log message for some time in your editor, it is
> > quite natural for you to decide that leaving the commit as-is is the
> > right thing [*3*] in your situation.  It may have been a better
> > design for the system to notice this situation and leave the commit
> > as-is, with an override option `--force` to allow users to forcibly
> > update the committer ident and timestamp in the commit header.  I am
> > not a `history reword` user (yet), but from the motivation you
> > described for this patch, I sense that the story is the same there.
>
> FWIW, in this situation I abort my editor (:cquit in Vim) so that the amend gets an error-valued exit code from the subprocess and aborts itself.
>
> Perhaps there could/should be a better side-channel for communicating that, though? I do not know how easy it is to tell other editors to « quit with errors ».

Well, I didn't know that I could exit with errors (:cq in NeoVim), can't say much about other editors, but It would be better to abort if the messages are the same and forget about editors.

Show 15 quoted lines
>
> > [Footnote]
> >
> > *1* Besides, doesn't "--update-refs" in "rebase -i" allow you to
> >     adjust the branches?
> >
> > *2* But it is an established behaviour people _rely_ on, so even
> >     though it may have been better if these commands behaved
> >     differently, it probably is a bit too late to change it now.
> >
> > *3* This includes the case where the original author is especially
> >     difficult to work with and would complain any change to their
> >     commits, even if the only change you made for them is a
> >     typofix.  Fixing a small typo/grammo may not be worth your time
> >     and unpleasant exchanges with them after touching their commit.

Thanks, Pablo

Pablo SabaterJun 9, 2026, 10:14 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

El lun, 8 jun 2026 a las 14:16, Junio C Hamano (<gitster@pobox.com>) escribió:
>
[snip]
Show 28 quoted lines
>
> `git rebase -i` may have an excuse that because it, unlike "git
> commit --amend", operates on multiple commits by design.  A single
> "--force" option given to the command would not have worked as an
> escape hatch to allow the user to tell the command "in this reword
> of this particular commit, I ended up doing nothing, but I still
> want an updated committer log timestamp".  Perhaps giving the
> "--force" (or --force-rewrite") option at "rebase --continue" time
> may work, but in any case, unless we plan to transition to these
> "better" default behaviour at a big version boundary, speculating
> what a "better" behaviour would have been may be fun but not very
> productive.
>
>
> [Footnote]
>
>  *1* Besides, doesn't "--update-refs" in "rebase -i" allow you to
>      adjust the branches?
>
>  *2* But it is an established behaviour people _rely_ on, so even
>      though it may have been better if these commands behaved
>      differently, it probably is a bit too late to change it now.
>
>  *3* This includes the case where the original author is especially
>      difficult to work with and would complain any change to their
>      commits, even if the only change you made for them is a
>      typofix.  Fixing a small typo/grammo may not be worth your time
>      and unpleasant exchanges with them after touching their commit.

True, after reading it, history being more costly or the in memory are not good args. I do agree that these commands that do reword should check if the reword ends up being the same message, given that history is a new command we can have it from the start so users do not really expect other behavior. About the --force sounds good to me. I could seek to implement it in this series if it's ok. The footnote 3 is indeed a good example haha, but yeah, why rewrite the history unnecessarily.

Thanks, Pablo

Kristoffer HaugsbakkJun 9, 2026, 10:30 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

On Tue, Jun 9, 2026, at 12:14, Pablo Sabater wrote:
Show 36 quoted lines
> El lun, 8 jun 2026 a las 14:16, Junio C Hamano (<gitster@pobox.com>) escribió:
>>
> [snip]
>>
>> `git rebase -i` may have an excuse that because it, unlike "git
>> commit --amend", operates on multiple commits by design.  A single
>> "--force" option given to the command would not have worked as an
>> escape hatch to allow the user to tell the command "in this reword
>> of this particular commit, I ended up doing nothing, but I still
>> want an updated committer log timestamp".  Perhaps giving the
>> "--force" (or --force-rewrite") option at "rebase --continue" time
>> may work, but in any case, unless we plan to transition to these
>> "better" default behaviour at a big version boundary, speculating
>> what a "better" behaviour would have been may be fun but not very
>> productive.
>>
>>
>> [Footnote]
>>
>>  *1* Besides, doesn't "--update-refs" in "rebase -i" allow you to
>>      adjust the branches?
>>
>>  *2* But it is an established behaviour people _rely_ on, so even
>>      though it may have been better if these commands behaved
>>      differently, it probably is a bit too late to change it now.
>>
>>  *3* This includes the case where the original author is especially
>>      difficult to work with and would complain any change to their
>>      commits, even if the only change you made for them is a
>>      typofix.  Fixing a small typo/grammo may not be worth your time
>>      and unpleasant exchanges with them after touching their commit.
>
>[snip]
>
> About the --force sounds good to me. I could seek to implement it in
> this series if it's ok.

When starting without historical baggage anyway, I have doubts about the `--force` name in general. This often just begs me to ask what it is forcing. Why not name the thing that is being forced? Verbosity shouldn’t be a problem for a “force” option. So `--force-rewrite` if you are forcing new commits to be created (like already mentioned).

See git-clean(1) which has two levels of `--force`.
> The footnote 3 is indeed a good example haha, but yeah, why rewrite
> the history unnecessarily.
Pablo SabaterJun 9, 2026, 10:42 UTC in reply to Pablo Sabater on lore

[PATCH RFC v2 0/2] builtin/history: abort reword on same message

This short series aims to improve the behavior of `git history reword` to abort when the new commit message is the same as the original, avoiding unnecessary history rewrites.

`git commit --amend` and `git rebase -i` with reword share this flaw but changing them faces not just technical challenges but also breaks what people are used to, so that is not a viable option. Let's take the opportunity that `git history` is a new command and handle this correctly from the start.

This is made so any other future subcommand or option that does want this behavior just has to add the abort flag.

A questions I have is why don't we want this abort behavior on `git history fixup --reedit-message` it makes more sense on `git history reword` because if the message is the same then it has nothing to do while fixup can still have files to update, but --reedit-message is still a redundant option there.

Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
Changes in v2:
- Changed the reason on why is this needed.
- Changed tests with same message to use GIT_EDITOR=true instead of the
  script.
- Abort on same message only happens when its own flag is set so no
  other subcommand that does not want this behavior and depend on
  commit_tree_ext() is affected.
- Dropped the feedback on successful reword for another series.
---
Pablo Sabater (2):
      builtin/history: refactor function signature
      builtin/history: abort reword on same message
 builtin/history.c         | 21 ++++++++++++++++++---
 t/t3451-history-reword.sh | 16 ++++++++++++++++
 t/t3453-history-fixup.sh  | 22 ++++++++++++++++++++++
 3 files changed, 56 insertions(+), 3 deletions(-)
---
base-commit: 9ac3f193c05c2237e2b14ebaa1149e9fc8a1abe0
change-id: 20260607-ps-history-reword-fcb70eaa4aa9

Best regards, -- Pablo Sabater <pabloosabaterr@gmail.com>

Pablo SabaterJun 9, 2026, 10:42 UTC in reply to Pablo Sabater on lore

[PATCH RFC v2 1/2] builtin/history: refactor function signature

commit_tree_with_edited_message() calls commit_tree_ext() with the flag COMMIT_TREE_EDIT_MESSAGE hardcoded and we can't set new flags on callers like cmd_history_reword() to choose their own flags.

This refactor is needed for a subsequent commit.

Refactor commit_tree_with_edited_message() signature to accept flags which are passed down to commit_tree_ext() instead of the hardcoded one.

Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
 builtin/history.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Show changes to builtin/history.c +6 −3
diff --git a/builtin/history.c b/builtin/history.c
index 0fc06fb204..b3e2e5270d 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -160,7 +160,8 @@ static int commit_tree_ext(struct repository *repo,
 static int commit_tree_with_edited_message(struct repository *repo,
 					   const char *action,
 					   struct commit *original,
-					   struct commit **out)
+					   struct commit **out,
+					   enum commit_tree_flags flags)
 {
 	struct object_id parent_tree_oid;
 	const struct object_id *tree_oid;
@@ -181,7 +182,7 @@ static int commit_tree_with_edited_message(struct repository *repo,
 	}
 
 	return commit_tree_ext(repo, action, original, original->parents,
-			       &parent_tree_oid, tree_oid, out, COMMIT_TREE_EDIT_MESSAGE);
+			       &parent_tree_oid, tree_oid, out, flags);
 }
 
 enum ref_action {
@@ -692,6 +693,7 @@ static int cmd_history_reword(int argc,
 	struct strbuf reflog_msg = STRBUF_INIT;
 	struct commit *original, *rewritten;
 	struct rev_info revs = { 0 };
+	enum commit_tree_flags flags = COMMIT_TREE_EDIT_MESSAGE;
 	int ret;
 
 	argc = parse_options(argc, argv, prefix, options, usage, 0);
@@ -714,7 +716,8 @@ static int cmd_history_reword(int argc,
 	if (ret)
 		goto out;
 
-	ret = commit_tree_with_edited_message(repo, "reworded", original, &rewritten);
+	ret = commit_tree_with_edited_message(repo, "reworded", original,
+					      &rewritten, flags);
 	if (ret < 0) {
 		ret = error(_("failed writing reworded commit"));
 		goto out;
-- 
2.54.0
Pablo SabaterJun 9, 2026, 10:42 UTC in reply to Pablo Sabater on lore

[PATCH RFC v2 2/2] builtin/history: abort reword on same message

When using `git history reword <commit>` if the new message is the same as the original, it continues and rewrites the history when nothing changed.

`git commit --amend` and `git rebase -i` with reword share this behavior and it is wrong as well, but changing them breaks what people are used to. Take the opportunity of `git history` being a new command and handle it correctly from the start.

Create COMMIT_TREE_ABORT_ON_SAME_MESSAGE and make a check for if the messages are the same and the flag is set so other subcommands like fixup that do not want this behavior just don't send the abort flag.

Make commit_tree_ext() return 1 when facing the same message so its callers can choose what to do.

Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
 builtin/history.c         | 14 +++++++++++++-
 t/t3451-history-reword.sh | 16 ++++++++++++++++
 t/t3453-history-fixup.sh  | 22 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)
Show changes to 3 files +51 −1

builtin/history.c, t/t3451-history-reword.sh, t/t3453-history-fixup.sh

diff --git a/builtin/history.c b/builtin/history.c
index b3e2e5270d..be07690da4 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -96,6 +96,7 @@ static int fill_commit_message(struct repository *repo,
 
 enum commit_tree_flags {
 	COMMIT_TREE_EDIT_MESSAGE = (1 << 0),
+	COMMIT_TREE_ABORT_ON_SAME_MESSAGE = (1 << 1),
 };
 
 static int commit_tree_ext(struct repository *repo,
@@ -135,6 +136,13 @@ static int commit_tree_ext(struct repository *repo,
 					  original_body, action, &commit_message);
 		if (ret < 0)
 			goto out;
+
+		if (flags & COMMIT_TREE_ABORT_ON_SAME_MESSAGE &&
+		    !strcmp(original_body, commit_message.buf)) {
+			fprintf(stderr, _("Message unchanged, aborting reword.\n"));
+			ret = 1;
+			goto out;
+		}
 	} else {
 		strbuf_addstr(&commit_message, original_body);
 	}
@@ -693,7 +701,8 @@ static int cmd_history_reword(int argc,
 	struct strbuf reflog_msg = STRBUF_INIT;
 	struct commit *original, *rewritten;
 	struct rev_info revs = { 0 };
-	enum commit_tree_flags flags = COMMIT_TREE_EDIT_MESSAGE;
+	enum commit_tree_flags flags = COMMIT_TREE_EDIT_MESSAGE |
+				       COMMIT_TREE_ABORT_ON_SAME_MESSAGE;
 	int ret;
 
 	argc = parse_options(argc, argv, prefix, options, usage, 0);
@@ -721,6 +730,9 @@ static int cmd_history_reword(int argc,
 	if (ret < 0) {
 		ret = error(_("failed writing reworded commit"));
 		goto out;
+	} else if (ret == 1) {
+		ret = 0;
+		goto out;
 	}
 
 	strbuf_addf(&reflog_msg, "reword: updating %s", argv[0]);
diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
index de7b357685..6e0e278c42 100755
--- a/t/t3451-history-reword.sh
+++ b/t/t3451-history-reword.sh
@@ -396,4 +396,20 @@ test_expect_success 'retains changes in the worktree and index' '
 	)
 '
 
+test_expect_success 'aborts if the commit message is the same' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit first &&
+		test_commit second &&
+
+		git rev-parse HEAD >oid-before &&
+		GIT_EDITOR=true git history reword HEAD 2>err &&
+		git rev-parse HEAD >oid-after &&
+		test_cmp oid-before oid-after &&
+		test_grep "Message unchanged" err
+	)
+'
+
 test_done
diff --git a/t/t3453-history-fixup.sh b/t/t3453-history-fixup.sh
index 868298e248..9f9a3c93de 100755
--- a/t/t3453-history-fixup.sh
+++ b/t/t3453-history-fixup.sh
@@ -443,6 +443,28 @@ test_expect_success '--reedit-message opens editor for the commit message' '
 	)
 '
 
+test_expect_success 'fixup --reedit-message does not abort with the same commit message' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		echo content > file.txt &&
+		git add file.txt &&
+		git commit -m "add file" &&
+
+		echo fix >>file.txt &&
+		git add file.txt &&
+		GIT_EDITOR=true git history fixup --reedit-message HEAD &&
+		expect_changes --branches <<-\EOF
+		add file
+		2	0	file.txt
+		initial
+		1	0	initial.t
+		EOF
+	)
+'
+
 test_expect_success 'retains unstaged working tree changes after fixup' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&
-- 
2.54.0
Junio C HamanoJun 9, 2026, 13:21 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

Pablo Sabater <pabloosabaterr@gmail.com> writes:
> True, after reading it, history being more costly or the in memory are
> not good args.

And no argument, including that history is new, is a good excuse to make these three things inconsistent, period.

One of the patches in your updated iteration claims
    When using `git history reword <commit>` if the new message is the same
    as the original, it continues and rewrites the history when nothing
    changed.
    `git commit --amend` and `git rebase -i` with reword share this behavior
    and it is wrong as well, but changing them breaks what people are used
    to. Take the opportunity of `git history` being a new command and handle
    it correctly from the start.
and I think this is a totally wrong attitude to go about this.

I may have said that it may have been a better default to try hard to avoid making a change that is a no-op, other than that it changes committer timestamp, while making the current "always create a new commit object" behaviour optionally available, for these three commands, and cited that the behaviour of 'pick' in 'rebase -i' that avoids unnecessary rewrite as an example of a good practice.

But I do not think the existing behaviour to always rewrite is *wrong* at all. It may be wrong not to offer the other choice of pretending no content change means no commit object change, but that is a different story.

I also do not think *aborting* only when the message happens to be the same is a valid mode of operation at all.

The most sensible first step, I think, is to add a new command line option to "git history" (which will gain more history editing subcommands) that tells the command to leave the original history as-is when the only change rewriting commits would make would be to the committer ident or timestamp information. If in a future a new replace-tree subcommand is added, e.g. if

    $ git history replace-tree HEAD~20 HEAD~27^{tree}

were a command to rewrite the history in such a way that 20th direct ancestor of the current HEAD had a tree object HEAD~27^{tree}, by derfault the command _should_ rewrite HEAD~10 and everything that has it as an ancestor. With the "--avoid-unnecsssary-rewrite" optimization feature on, however, it may silently become a no-op when HEAD~27^{tree} happened to be the same tree as HEAD~20^{tree} so the only difference between rewritten and original HEAD~20 would be when that commit object was created and by whom.

And give the same option to "rebase -i" or "commit --amend". We can discuss, educate the users, and flip the default at a major version boundary, if the "avoid unnecessary rewrite" truly turns out to be a better default (right now it is merely our speculation, and we do not even know if the current behaviour is a worse default).

Phillip WoodJun 9, 2026, 13:25 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

Hi Pablo
On 09/06/2026 11:42, Pablo Sabater wrote:
Show 12 quoted lines
>   static int commit_tree_ext(struct repository *repo,
> @@ -135,6 +136,13 @@ static int commit_tree_ext(struct repository *repo,
>   					  original_body, action, &commit_message);
>   		if (ret < 0)
>   			goto out;
> +
> +		if (flags & COMMIT_TREE_ABORT_ON_SAME_MESSAGE &&
> +		    !strcmp(original_body, commit_message.buf)) {
> +			fprintf(stderr, _("Message unchanged, aborting reword.\n"));
> +			ret = 1;
> +			goto out;
> +		}

I wonder if we should check that the committer identity is unchanged as well in case anyone is using this to fix commits after committing with the wrong identity.

Aborting when the message and committer identity are unchanged seems like a good idea.

Thanks
Phillip
Show 82 quoted lines
>   	} else {
>   		strbuf_addstr(&commit_message, original_body);
>   	}
> @@ -693,7 +701,8 @@ static int cmd_history_reword(int argc,
>   	struct strbuf reflog_msg = STRBUF_INIT;
>   	struct commit *original, *rewritten;
>   	struct rev_info revs = { 0 };
> -	enum commit_tree_flags flags = COMMIT_TREE_EDIT_MESSAGE;
> +	enum commit_tree_flags flags = COMMIT_TREE_EDIT_MESSAGE |
> +				       COMMIT_TREE_ABORT_ON_SAME_MESSAGE;
>   	int ret;
>   
>   	argc = parse_options(argc, argv, prefix, options, usage, 0);
> @@ -721,6 +730,9 @@ static int cmd_history_reword(int argc,
>   	if (ret < 0) {
>   		ret = error(_("failed writing reworded commit"));
>   		goto out;
> +	} else if (ret == 1) {
> +		ret = 0;
> +		goto out;
>   	}
>   
>   	strbuf_addf(&reflog_msg, "reword: updating %s", argv[0]);
> diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
> index de7b357685..6e0e278c42 100755
> --- a/t/t3451-history-reword.sh
> +++ b/t/t3451-history-reword.sh
> @@ -396,4 +396,20 @@ test_expect_success 'retains changes in the worktree and index' '
>   	)
>   '
>   
> +test_expect_success 'aborts if the commit message is the same' '
> +	test_when_finished "rm -rf repo" &&
> +	git init repo &&
> +	(
> +		cd repo &&
> +		test_commit first &&
> +		test_commit second &&
> +
> +		git rev-parse HEAD >oid-before &&
> +		GIT_EDITOR=true git history reword HEAD 2>err &&
> +		git rev-parse HEAD >oid-after &&
> +		test_cmp oid-before oid-after &&
> +		test_grep "Message unchanged" err
> +	)
> +'
> +
>   test_done
> diff --git a/t/t3453-history-fixup.sh b/t/t3453-history-fixup.sh
> index 868298e248..9f9a3c93de 100755
> --- a/t/t3453-history-fixup.sh
> +++ b/t/t3453-history-fixup.sh
> @@ -443,6 +443,28 @@ test_expect_success '--reedit-message opens editor for the commit message' '
>   	)
>   '
>   
> +test_expect_success 'fixup --reedit-message does not abort with the same commit message' '
> +	test_when_finished "rm -rf repo" &&
> +	git init repo &&
> +	(
> +		cd repo &&
> +		test_commit initial &&
> +		echo content > file.txt &&
> +		git add file.txt &&
> +		git commit -m "add file" &&
> +
> +		echo fix >>file.txt &&
> +		git add file.txt &&
> +		GIT_EDITOR=true git history fixup --reedit-message HEAD &&
> +		expect_changes --branches <<-\EOF
> +		add file
> +		2	0	file.txt
> +		initial
> +		1	0	initial.t
> +		EOF
> +	)
> +'
> +
>   test_expect_success 'retains unstaged working tree changes after fixup' '
>   	test_when_finished "rm -rf repo" &&
>   	git init repo &&
> 
Pablo SabaterJun 9, 2026, 15:51 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message

El mar, 9 jun 2026 a las 15:21, Junio C Hamano (<gitster@pobox.com>) escribió:
Show 60 quoted lines
>
> Pablo Sabater <pabloosabaterr@gmail.com> writes:
>
> > True, after reading it, history being more costly or the in memory are
> > not good args.
>
> And no argument, including that history is new, is a good excuse to
> make these three things inconsistent, period.
>
> One of the patches in your updated iteration claims
>
>     When using `git history reword <commit>` if the new message is the same
>     as the original, it continues and rewrites the history when nothing
>     changed.
>
>     `git commit --amend` and `git rebase -i` with reword share this behavior
>     and it is wrong as well, but changing them breaks what people are used
>     to. Take the opportunity of `git history` being a new command and handle
>     it correctly from the start.
>
> and I think this is a totally wrong attitude to go about this.
>
> I may have said that it may have been a better default to try hard
> to avoid making a change that is a no-op, other than that it changes
> committer timestamp, while making the current "always create a new
> commit object" behaviour optionally available, for these three
> commands, and cited that the behaviour of 'pick' in 'rebase -i' that
> avoids unnecessary rewrite as an example of a good practice.
>
> But I do not think the existing behaviour to always rewrite is
> *wrong* at all.  It may be wrong not to offer the other choice of
> pretending no content change means no commit object change, but that
> is a different story.
>
> I also do not think *aborting* only when the message happens to be
> the same is a valid mode of operation at all.
>
> The most sensible first step, I think, is to add a new command line
> option to "git history" (which will gain more history editing
> subcommands) that tells the command to leave the original history
> as-is when the only change rewriting commits would make would be to
> the committer ident or timestamp information.  If in a future a new
> replace-tree subcommand is added, e.g. if
>
>     $ git history replace-tree HEAD~20 HEAD~27^{tree}
>
> were a command to rewrite the history in such a way that 20th direct
> ancestor of the current HEAD had a tree object HEAD~27^{tree}, by
> derfault the command _should_ rewrite HEAD~10 and everything that
> has it as an ancestor.  With the "--avoid-unnecsssary-rewrite"
> optimization feature on, however, it may silently become a no-op
> when HEAD~27^{tree} happened to be the same tree as HEAD~20^{tree}
> so the only difference between rewritten and original HEAD~20 would
> be when that commit object was created and by whom.
>
> And give the same option to "rebase -i" or "commit --amend".  We can
> discuss, educate the users, and flip the default at a major version
> boundary, if the "avoid unnecessary rewrite" truly turns out to be a
> better default (right now it is merely our speculation, and we do
> not even know if the current behaviour is a worse default).
Hi Junio,

Sorry about how I expressed myself. I didn't mean by wrong to be bad or anything similar, I just noticed this when testing `git history reword` and thought that I would like it this other way.

Saying that git history is new or I would like this to be different are not good arguments to have `git history` inconsistent with other commands.

My idea was more of a defensive thing, where you would need a "--force-rewrite" opt to explicitly change timestamps. But I see the point of having it in an `--avoid-unnecessary-rewrite` so without options it has the same behavior as other commands.

I'll try to express myself better in the next version and go with the opt direction.

Sorry again, Pablo

Junio C HamanoJun 9, 2026, 16:20 UTC in reply to Phillip Wood on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 22 quoted lines
> Hi Pablo
>
> On 09/06/2026 11:42, Pablo Sabater wrote:
>>   static int commit_tree_ext(struct repository *repo,
>> @@ -135,6 +136,13 @@ static int commit_tree_ext(struct repository *repo,
>>   					  original_body, action, &commit_message);
>>   		if (ret < 0)
>>   			goto out;
>> +
>> +		if (flags & COMMIT_TREE_ABORT_ON_SAME_MESSAGE &&
>> +		    !strcmp(original_body, commit_message.buf)) {
>> +			fprintf(stderr, _("Message unchanged, aborting reword.\n"));
>> +			ret = 1;
>> +			goto out;
>> +		}
>
> I wonder if we should check that the committer identity is unchanged as 
> well in case anyone is using this to fix commits after committing with 
> the wrong identity.
>
> Aborting when the message and committer identity are unchanged seems 
> like a good idea.

I am not sure why it would be a good idea. The user wanted to make the commit have this message, and the commit ended up having the same message as the user gave. That message may have been identical to what the commit originally had, or it may be different. Why is the former an abort-worthy event? A simple note, I may understand, but aborting with an error message?

Thanks.
Pablo SabaterJun 9, 2026, 17:12 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

El mar, 9 jun 2026 a las 18:20, Junio C Hamano (<gitster@pobox.com>) escribió:
Show 22 quoted lines
>
> Phillip Wood <phillip.wood123@gmail.com> writes:
>
> > Hi Pablo
> >
> > On 09/06/2026 11:42, Pablo Sabater wrote:
> >>   static int commit_tree_ext(struct repository *repo,
> >> @@ -135,6 +136,13 @@ static int commit_tree_ext(struct repository *repo,
> >>                                        original_body, action, &commit_message);
> >>              if (ret < 0)
> >>                      goto out;
> >> +
> >> +            if (flags & COMMIT_TREE_ABORT_ON_SAME_MESSAGE &&
> >> +                !strcmp(original_body, commit_message.buf)) {
> >> +                    fprintf(stderr, _("Message unchanged, aborting reword.\n"));
> >> +                    ret = 1;
> >> +                    goto out;
> >> +            }
> >
> > I wonder if we should check that the committer identity is unchanged as
> > well in case anyone is using this to fix commits after committing with
> > the wrong identity.

I think that if you reword a commit committed by someone else but end up with no changes I want it to be kept as it was.

Show 10 quoted lines
> >
> > Aborting when the message and committer identity are unchanged seems
> > like a good idea.
>
> I am not sure why it would be a good idea.  The user wanted to make
> the commit have this message, and the commit ended up having the
> same message as the user gave.  That message may have been identical
> to what the commit originally had, or it may be different.  Why is
> the former an abort-worthy event?  A simple note, I may understand,
> but aborting with an error message?

With what you said at [1], having this in an "--avoid-unnecessary-rewrite" I think that the abort might be too much as with the flag the user already expects this to happen and silent might be better.

By the way, I feel that "--avoid-unnecessary-rewrite" is too long, could it be something shorter? If not it could be set "-r" as the short and leave the long as it is.

>
> Thanks.
[1]: https://lore.kernel.org/git/xmqqtsrbsvcm.fsf@gitster.g/

Thanks, Pablo

Justin ToblerJun 9, 2026, 18:02 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

On 26/06/09 09:20AM, Junio C Hamano wrote:
Show 31 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
> > Hi Pablo
> >
> > On 09/06/2026 11:42, Pablo Sabater wrote:
> >>   static int commit_tree_ext(struct repository *repo,
> >> @@ -135,6 +136,13 @@ static int commit_tree_ext(struct repository *repo,
> >>   					  original_body, action, &commit_message);
> >>   		if (ret < 0)
> >>   			goto out;
> >> +
> >> +		if (flags & COMMIT_TREE_ABORT_ON_SAME_MESSAGE &&
> >> +		    !strcmp(original_body, commit_message.buf)) {
> >> +			fprintf(stderr, _("Message unchanged, aborting reword.\n"));
> >> +			ret = 1;
> >> +			goto out;
> >> +		}
> >
> > I wonder if we should check that the committer identity is unchanged as 
> > well in case anyone is using this to fix commits after committing with 
> > the wrong identity.
> >
> > Aborting when the message and committer identity are unchanged seems 
> > like a good idea.
> 
> I am not sure why it would be a good idea.  The user wanted to make
> the commit have this message, and the commit ended up having the
> same message as the user gave.  That message may have been identical
> to what the commit originally had, or it may be different.  Why is
> the former an abort-worthy event?  A simple note, I may understand,
> but aborting with an error message?
I can see a situation where a user performs:
  git history reword abcd1234

with the intention to modify a commit message, but then for some reason changes their mind and doesn't want history to change. Maybe the wrong commit was referenced, or they decide the current message is actually fine. From my understanding, there isn't a great way to abort rewording a commit during editing and thus the user would have to reset history afterwards if they care enough to go back to the previous point.

So I do see some value in a mechanism to abort rewriting a commit message. An unchanged commit message does seem like a reasonable signal to essentially abort the reword. I'm not sure committer identity should be taken into consideration though since it would inhibit a users ability to abort the reword if they ever touch a commit that they themselves are not the previous committer.

I don't think there is a need to have an error message though. Even in the case where the user leaves the commit message unchanged and history is left untouched, git-history(1) would be following exactly what the user instructed it to do. I don't really see why the user should care whether history was actually modified or not in such a scenario.

-Justin
Junio C HamanoJun 9, 2026, 19:17 UTC in reply to Pablo Sabater on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

Pablo Sabater <pabloosabaterr@gmail.com> writes:
Show 6 quoted lines
>> > I wonder if we should check that the committer identity is unchanged as
>> > well in case anyone is using this to fix commits after committing with
>> > the wrong identity.
>
> I think that if you reword a commit committed by someone else but end
> up with no changes I want it to be kept as it was.

That depends on the reason why the feature to "reword" the commit is being used, and the use case Phillip is talking about is a bit different.

A very common mistake a new user makes when starting a repository is to make commits before they realize that they used a wrong identity to create them. They are happy with what they committed, except that they want these commits to be attributed to user.{name,email} they corrected.

Also, people often use multiple identities (e.g., corp vs personal), and when making commits to the project for their employer they do not want to use their personal identity (and vice versa). After making a mistake to create commits under wrong identity, they want to fix these commits.

In such situations, there is no room for leaving the committer name as "someone else". The user wants to get rid of the "someone else"s identity out of these commits.

Junio C HamanoJun 9, 2026, 19:30 UTC in reply to Justin Tobler on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

Justin Tobler <jltobler@gmail.com> writes:
Show 13 quoted lines
> I can see a situation where a user performs:
>
>   git history reword abcd1234
>
> with the intention to modify a commit message, but then for some reason
> changes their mind and doesn't want history to change. Maybe the wrong
> commit was referenced, or they decide the current message is actually
> fine. From my understanding, there isn't a great way to abort rewording
> a commit during editing and thus the user would have to reset history
> afterwards if they care enough to go back to the previous point.
>
> So I do see some value in a mechanism to abort rewriting a commit
> message.

I think we are saying the same thing in different ways. I want to see that command "succeed" either case (normally we create a new commit object because we record an updated committer timestamp, but if there is no need to create a new commit object only to record an updated committer timestamp, we may choose not to and leave the history intact) and I do not want it to *abort*.

The mechanism to do so may be exactly the same, i.e., accept an updated log message, then try to "hash-object" (without -w) the commit object with everything, except for the updated commit log message, taken from the original commit, plus the updated log message. And if the resulting hash is the same as the original, do not do anything further and return happily. Aborting sounds more like complaining loudly "baa, you asked me to reword but you gave me the same message? is anything wrong with you?" with non-zero exit status, which I think the user does not deserve in such a case.

Justin ToblerJun 9, 2026, 20:14 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

On 26/06/09 12:30PM, Junio C Hamano wrote:
Show 32 quoted lines
> Justin Tobler <jltobler@gmail.com> writes:
> 
> > I can see a situation where a user performs:
> >
> >   git history reword abcd1234
> >
> > with the intention to modify a commit message, but then for some reason
> > changes their mind and doesn't want history to change. Maybe the wrong
> > commit was referenced, or they decide the current message is actually
> > fine. From my understanding, there isn't a great way to abort rewording
> > a commit during editing and thus the user would have to reset history
> > afterwards if they care enough to go back to the previous point.
> >
> > So I do see some value in a mechanism to abort rewriting a commit
> > message.
> 
> I think we are saying the same thing in different ways.  I want to
> see that command "succeed" either case (normally we create a new
> commit object because we record an updated committer timestamp, but
> if there is no need to create a new commit object only to record an
> updated committer timestamp, we may choose not to and leave the
> history intact) and I do not want it to *abort*.
> 
> The mechanism to do so may be exactly the same, i.e., accept an
> updated log message, then try to "hash-object" (without -w) the
> commit object with everything, except for the updated commit log
> message, taken from the original commit, plus the updated log
> message.  And if the resulting hash is the same as the original, do
> not do anything further and return happily.  Aborting sounds more
> like complaining loudly "baa, you asked me to reword but you gave me
> the same message? is anything wrong with you?" with non-zero exit
> status, which I think the user does not deserve in such a case.

Yes, I completely agree. If the user doesn't update the commit message, for whatever reason, that should still be considered a success since it follows the user's intent. I don't think it makes sense to exit with a non-zero code in such cases. I would also question if we should print any message/note to the user at all for the same reasons.

-Justin
Patrick SteinhardtJun 10, 2026, 07:03 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

On Tue, Jun 09, 2026 at 12:17:51PM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> Pablo Sabater <pabloosabaterr@gmail.com> writes:
> 
> >> > I wonder if we should check that the committer identity is unchanged as
> >> > well in case anyone is using this to fix commits after committing with
> >> > the wrong identity.
> >
> > I think that if you reword a commit committed by someone else but end
> > up with no changes I want it to be kept as it was.
> 
> That depends on the reason why the feature to "reword" the commit is
> being used, and the use case Phillip is talking about is a bit
> different.

So the answer is "it depends". Maybe we should do handle this the same as git-commit(1) does with its "--reset-author" flag?

Patrick
Phillip WoodJun 10, 2026, 09:24 UTC in reply to Junio C Hamano on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

On 09/06/2026 17:20, Junio C Hamano wrote:
Show 31 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> Hi Pablo
>>
>> On 09/06/2026 11:42, Pablo Sabater wrote:
>>>    static int commit_tree_ext(struct repository *repo,
>>> @@ -135,6 +136,13 @@ static int commit_tree_ext(struct repository *repo,
>>>    					  original_body, action, &commit_message);
>>>    		if (ret < 0)
>>>    			goto out;
>>> +
>>> +		if (flags & COMMIT_TREE_ABORT_ON_SAME_MESSAGE &&
>>> +		    !strcmp(original_body, commit_message.buf)) {
>>> +			fprintf(stderr, _("Message unchanged, aborting reword.\n"));
>>> +			ret = 1;
>>> +			goto out;
>>> +		}
>>
>> I wonder if we should check that the committer identity is unchanged as
>> well in case anyone is using this to fix commits after committing with
>> the wrong identity.
>>
>> Aborting when the message and committer identity are unchanged seems
>> like a good idea.
> 
> I am not sure why it would be a good idea.  The user wanted to make
> the commit have this message, and the commit ended up having the
> same message as the user gave.  That message may have been identical
> to what the commit originally had, or it may be different.  Why is
> the former an abort-worthy event?  A simple note, I may understand,
> but aborting with an error message?

What I really meant was skipping rewriting history makes sense, I don't have a strong opinion on the exit code. My feeling is that some kind of message saying we haven't rewritten anything probably a good idea.

Thanks
Phillip
Phillip WoodJun 10, 2026, 09:33 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

Hi Patrick
On 10/06/2026 08:03, Patrick Steinhardt wrote:
Show 16 quoted lines
> On Tue, Jun 09, 2026 at 12:17:51PM -0700, Junio C Hamano wrote:
>> Pablo Sabater <pabloosabaterr@gmail.com> writes:
>>
>>>>> I wonder if we should check that the committer identity is unchanged as
>>>>> well in case anyone is using this to fix commits after committing with
>>>>> the wrong identity.
>>>
>>> I think that if you reword a commit committed by someone else but end
>>> up with no changes I want it to be kept as it was.
>>
>> That depends on the reason why the feature to "reword" the commit is
>> being used, and the use case Phillip is talking about is a bit
>> different.
> 
> So the answer is "it depends". Maybe we should do handle this the same
> as git-commit(1) does with its "--reset-author" flag?

For the case I was talking about we'd want to reset the committer but I agree that making "reset the committer" explicit and just comparing the old and new messages when deciding whether to skip rewriting is a good way forward.

Thanks
Phillip
Junio C HamanoJun 10, 2026, 16:02 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH RFC v2 2/2] builtin/history: abort reword on same message

Patrick Steinhardt <ps@pks.im> writes:
Show 16 quoted lines
> On Tue, Jun 09, 2026 at 12:17:51PM -0700, Junio C Hamano wrote:
>> Pablo Sabater <pabloosabaterr@gmail.com> writes:
>> 
>> >> > I wonder if we should check that the committer identity is unchanged as
>> >> > well in case anyone is using this to fix commits after committing with
>> >> > the wrong identity.
>> >
>> > I think that if you reword a commit committed by someone else but end
>> > up with no changes I want it to be kept as it was.
>> 
>> That depends on the reason why the feature to "reword" the commit is
>> being used, and the use case Phillip is talking about is a bit
>> different.
>
> So the answer is "it depends". Maybe we should do handle this the same
> as git-commit(1) does with its "--reset-author" flag?

Interesting. I was mostly focusing on the committer identity, but the same argument of courese also applies to the author identity.

Having said that, if the user who used to commit others' patches under a wrong identity (i.e., the only thing incorrect about these commits is the committer identity, and author identity of them are not to be updated), "--reset-author" would not be usable, as they want to keep the authorship information recorded. I think

 (1) in the shorter term, always create a new commit by default even
     if the only difference were the committer timestamp.  But add a
     mechanism to allow users to tell the tool to skip the update
     in such a case.
 (2) at a big version bump, flip the default, making the "always
     create a new commit" an optional feature.

would be the way to go, and the way to trigger that mechanism needs to be separate from "--reset-author".

Thanks.
Dominique MartinetJul 7, 2026, 05:09 UTC in reply to Ben Knoble on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

[context: I just played with git history reword/fixup and dug through archives for anything like this, so chiming in. First, thanks for the new git history commands, they all look promising!]

Ben Knoble wrote on Mon, Jun 08, 2026 at 12:47:41PM -0400:
>>> Do other commands in "git history" (split is in 'master', drop and
>>> fixup are cooking) behave with similar verbosity?  Consistency within
>>> the same "history" umbrella matters more than being similar with
>>> other commands that can be used for similar purposes.

I agree with the sentiment of needing consistency, but rather than say "the other commands are not verbose" (as they are) I'd say they're new enough we can afford to "make them all verbose" instead.

In particular, for git history reword there is an editor opening up, so I didn't have much trouble assuming silence was success, but I was disturbed by `git history fixup` which just returns immediately (much faster than rebase) with no feedback at all.

Show 13 quoted lines
>> They do not, they are thought with the rule of silence in mind.
>> However I think that this output is valuable information I might have
>> explained myself better at [1] but my thought is:
>> 
>> git history reword aabb
>> 
>> Now that I have my commit aabb rewritten I want to check it again just
>> to make sure I did what I wanted correctly,
>
> Some thoughts:
> 
> - If the rewritten commit is an ancestor of HEAD, look at the log of HEAD@{1} or the log between HEAD and the aforementioned reflog entry. (git-range-diff may also be helpful there.)
> - Similarly, if the rewritten commit is reachable from some ref R, check R@{1} etc. 

During my quick tests I was surprised with how git history reword/fixup behave with commits that aren't ancestors of HEAD/any branch (that can happen for example if you print `git log --oneline` once and refer to it after editing.

This transcript is a bit ugly but should illustrate the issue:
```
$ git init
Initialized empty Git repository in ...test/.git/
$ echo a > aa
$ git add aa
$ git commit -m init
[master (root-commit) 62884dc4d43c] init
 1 file changed, 1 insertion(+)
 create mode 100644 aa
$ echo b > b
$ git add b
$ git commit -m b
[master 058294f87a36] b
 1 file changed, 1 insertion(+)
 create mode 100644 b
$ echo c > c
$ git add c
$ git commit -m c
[master 0c4ad0c9337c] c
 1 file changed, 1 insertion(+)
 create mode 100644 c
$ git log --oneline --graph
* 0c4ad0c9337c (HEAD -> master) c
* 058294f87a36 b
* 62884dc4d43c init
$ echo d > d
$ git add d
$ git history fixup HEAD^
$ echo e > e
$ git add e
$ git history fixup 058294f87a36
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   e
$ git history reword 058294f87a36
(editor showed up, commit message modified and saved)
$ git log --oneline --graph
* 5cc5551381a3 (HEAD -> master) c
* 0b7ab36bf167 b
* 62884dc4d43c init
```
-> fixup didn't show any message (and exited with 0), but didn't unstage
the hunk either and didn't do anything, so one cannot differentiate with
the fixup actually happening
-> reword showed up editor but didn't actually do anything visible
(probably did create a new commit somewhere that's unreachable?)

So I agree with Pablo's suggestion: printing old/new short hash on success would help visualy confirming something worked.

... But it might be worth to ensure that the commit has any ref we can handle (if --update-refs is set then the commit we edit is ancestor to some branch, if not set then it must be an ancestor of HEAD)

What do you think?
-- 
Dominique Martinet | Asmadeus
D. Ben KnobleJul 7, 2026, 16:10 UTC in reply to Dominique Martinet on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

On Tue, Jul 7, 2026 at 1:09 AM Dominique Martinet <asmadeus@codewreck.org> wrote:

Show 6 quoted lines
>
> [context: I just played with git history reword/fixup and dug through
> archives for anything like this, so chiming in.
> First, thanks for the new git history commands, they all look promising!]
>
> Ben Knoble wrote on Mon, Jun 08, 2026 at 12:47:41PM -0400:
[snip]
Show 18 quoted lines
> >> They do not, they are thought with the rule of silence in mind.
> >> However I think that this output is valuable information I might have
> >> explained myself better at [1] but my thought is:
> >>
> >> git history reword aabb
> >>
> >> Now that I have my commit aabb rewritten I want to check it again just
> >> to make sure I did what I wanted correctly,
> >
> > Some thoughts:
> >
> > - If the rewritten commit is an ancestor of HEAD, look at the log of HEAD@{1} or the log between HEAD and the aforementioned reflog entry. (git-range-diff may also be helpful there.)
> > - Similarly, if the rewritten commit is reachable from some ref R, check R@{1} etc.
>
> During my quick tests I was surprised with how git history reword/fixup
> behave with commits that aren't ancestors of HEAD/any branch (that can
> happen for example if you print `git log --oneline` once and refer to it
> after editing.
Indeed, this is a bit of a "trap":
Show 49 quoted lines
> This transcript is a bit ugly but should illustrate the issue:
> ```
> $ git init
> Initialized empty Git repository in ...test/.git/
> $ echo a > aa
> $ git add aa
> $ git commit -m init
> [master (root-commit) 62884dc4d43c] init
>  1 file changed, 1 insertion(+)
>  create mode 100644 aa
> $ echo b > b
> $ git add b
> $ git commit -m b
> [master 058294f87a36] b
>  1 file changed, 1 insertion(+)
>  create mode 100644 b
> $ echo c > c
> $ git add c
> $ git commit -m c
> [master 0c4ad0c9337c] c
>  1 file changed, 1 insertion(+)
>  create mode 100644 c
> $ git log --oneline --graph
> * 0c4ad0c9337c (HEAD -> master) c
> * 058294f87a36 b
> * 62884dc4d43c init
> $ echo d > d
> $ git add d
> $ git history fixup HEAD^
> $ echo e > e
> $ git add e
> $ git history fixup 058294f87a36
> $ git status
> On branch master
> Changes to be committed:
>   (use "git restore --staged <file>..." to unstage)
>         new file:   e
> $ git history reword 058294f87a36
> (editor showed up, commit message modified and saved)
> $ git log --oneline --graph
> * 5cc5551381a3 (HEAD -> master) c
> * 0b7ab36bf167 b
> * 62884dc4d43c init
> ```
> -> fixup didn't show any message (and exited with 0), but didn't unstage
> the hunk either and didn't do anything, so one cannot differentiate with
> the fixup actually happening
> -> reword showed up editor but didn't actually do anything visible
> (probably did create a new commit somewhere that's unreachable?)

I think what probably happened here (and what you might find with `git fsck` for example) is that you have new commit objects in chains corresponding to those operations, but no refs were rewritten.

> So I agree with Pablo's suggestion: printing old/new short hash on
> success would help visualy confirming something worked.

I think we have the machinery for this (see --update-refs=print for git-replay, for example), but I'm surprised to learn that we don't accept --update-refs=print for history.

In any case, I second the "we should emit something"—I wonder what, though.
- In the case of rewritten refs, we might like to emit the list of
rewrites, a bit like a fetch or push will do: "+ $old...$new $ref
(forced update)" or something
- For new objects that aren't pointed to… maybe silence is a better
indicator that "we didn't do what you intended"? Or we could just
print the new commit objects "$new [unreferenced object]" or something
Show 5 quoted lines
> ... But it might be worth to ensure that the commit has any ref we can
> handle (if --update-refs is set then the commit we edit is ancestor to
> some branch, if not set then it must be an ancestor of HEAD)
>
> What do you think?

I don't think it's worth restricting the operation (I can imagine a use case where someone creates an unpointed-to object and later makes the ref, even if that's a bit weird), but

- we could have a "strict" mode that ensured inputs are pointed to
- we could warn when only unreferenced objects are rewritten

? I see git-history as very "porcelain"/user-focused, so I think it's feasible to add output niceties (and optionally a quiet mode to suppress the messages).

-- 
D. Ben Knoble
Patrick SteinhardtJul 8, 2026, 12:04 UTC in reply to D. Ben Knoble on lore

Re: [PATCH RFC 2/2] builtin/history: print feedback after successful reword

On Tue, Jul 07, 2026 at 12:10:12PM -0400, D. Ben Knoble wrote:
> On Tue, Jul 7, 2026 at 1:09 AM Dominique Martinet
> <asmadeus@codewreck.org> wrote:
[snip]
Show 15 quoted lines
> > So I agree with Pablo's suggestion: printing old/new short hash on
> > success would help visualy confirming something worked.
> 
> I think we have the machinery for this (see --update-refs=print for
> git-replay, for example), but I'm surprised to learn that we don't
> accept --update-refs=print for history.
> 
> In any case, I second the "we should emit something"—I wonder what, though.
> 
> - In the case of rewritten refs, we might like to emit the list of
> rewrites, a bit like a fetch or push will do: "+ $old...$new $ref
> (forced update)" or something
> - For new objects that aren't pointed to… maybe silence is a better
> indicator that "we didn't do what you intended"? Or we could just
> print the new commit objects "$new [unreferenced object]" or something

That's exactly my issue, as well. I'm slightly in favor of not writing anything, but if we're able to figure out how exactly to represent results to users in a nice and consistent way then I'm very happy to change my opinion.

But that definitely needs to account not only for the case where the current HEAD gets rewritten, but it needs to account for any reference (including detached HEAD) that may be updated along the way.

Show 16 quoted lines
> > ... But it might be worth to ensure that the commit has any ref we can
> > handle (if --update-refs is set then the commit we edit is ancestor to
> > some branch, if not set then it must be an ancestor of HEAD)
> >
> > What do you think?
> 
> I don't think it's worth restricting the operation (I can imagine a
> use case where someone creates an unpointed-to object and later makes
> the ref, even if that's a bit weird), but
> 
> - we could have a "strict" mode that ensured inputs are pointed to
> - we could warn when only unreferenced objects are rewritten
> 
> ? I see git-history as very "porcelain"/user-focused, so I think it's
> feasible to add output niceties (and optionally a quiet mode to
> suppress the messages).

Yeah, I don't see any issue with having such a "strict" mode, either. But I definitely don't want to enforce "arbitrary" restrictions that require the user to work around them. It's intentional that you can rewrite history of commits that aren't even reachable from HEAD.

It might be sensible to even make the strict mode the default, where you need to pass a switch to rewrite commits that are not reachable from HEAD. But if so, we need to have a switch that disables this mode.

Patrick

Back to recent threads