Re: [PATCH RFC 1/2] builtin/history: abort reword on unchanged message
- From
Pablo Sabater <pabloosabaterr@gmail.com>
- Date
- Jun 8, 2026, 10:52 UTC
- Message-ID
- <CAN5EUNSAOMRvmLGVfzQiwWoOn9VGNVU5rVMZizOryn_q2fbCNA@mail.gmail.com>
- In-Reply-To
- <aiaLxNwGPko5HS2G@pks.im>
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