Re: [PATCH v7 0/5] history: add squash subcommand to fold a range
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 6, 2026, 20:42 UTC
- Message-ID
- <xmqqse5v97e8.fsf@gitster.g>
- In-Reply-To
- <pull.2337.v7.git.git.1783327849.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> Adds git history squash <revision-range> to fold a range of commits.
What I saw in the range-diff looked all reasonable.
Show 16 quoted lines
> 3: 811e393ab4 ! 3: cf3346a1cd history: add squash subcommand to fold a range > @@ Commit message > Add "git history squash <revision-range>" to do this directly. It folds > every commit in the range into the oldest one, keeping that commit's > message and authorship and taking the tree of the newest commit, then > - replays the commits above the range on top. fixup!, squash! and amend! > - commits are folded like any other and are not interpreted, so the > - squashed message comes from the oldest commit, or from an editor with > - --reedit-message. > + replays the commits above the range on top. The squashed message comes > + from the oldest commit, or from an editor with --reedit-message. As that > + message is reused, a range whose oldest commit is a fixup!, squash! or > + amend! is refused, since the marker's target cannot be in the range. > ... > -+git history squash <revision-range> [--dry-run] [--update-refs=(branches|head)] [--reedit-message] > ++git history squash [--dry-run] [--update-refs=(branches|head)] [--reedit-message] <revision-range>
Show 16 quoted lines
> ++static int reject_fixupish_oldest(struct repository *repo,
> ++ struct commit *oldest)
> ++{
> ++ const char *message, *subject;
> ++ int ret = 0;
> ++
> ++ message = repo_logmsg_reencode(repo, oldest, NULL, NULL);
> ++ find_commit_subject(message, &subject);
> ++ if (starts_with(subject, "fixup! ") ||
> ++ starts_with(subject, "squash! ") ||
> ++ starts_with(subject, "amend! "))
> ++ ret = error(_("the range begins with a fixup!, squash! or amend! "
> ++ "commit whose target is not in the range"));
> ++ repo_unuse_commit_buffer(repo, oldest, message);
> ++ return ret;
> ++}Nice. I often see myself getting rescued by the corresponding sanity checks in the sequencer.
Will replace. Thanks.