Re: [PATCH v3 3/4] history: add squash subcommand to fold a range
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 18, 2026, 20:30 UTC
- Message-ID
- <xmqq7bnvr3qb.fsf@gitster.g>
- In-Reply-To
- <66b2f49fb427c7328136b2d440dc7461b97fb4e0.1781810227.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> +static int cmd_history_squash(int argc,
> + const char **argv,
> + const char *prefix,
> + struct repository *repo)
> +{
> + base_tree_oid = &repo_get_commit_tree(repo, base)->object.oid;
> + tip_tree_oid = &repo_get_commit_tree(repo, tip)->object.oid;
> + commit_list_append(base, &parents);
> +
> + ret = commit_tree_ext(repo, "squash", oldest, NULL, parents,
> + base_tree_oid, tip_tree_oid, &rewritten, flags);We use the tree object taken from the commit at the top end of the range, and create a new commit directly on top of the boundary commit beyond the bottom of the range, using the message from the commit at the bottom of the range. No need to go through the rigmarole of replaying commits in the range stepwise like sequencer does, since we are not transplanting the history on top of a different tree at all. Very nice.
When I do drunken-walk development to build many commits, making detour to arrive at an ideal state, the key message is often not in the bottommost commit but somewhere in the middle where I discovered why my initial attempt were wrong and discovered a much better solution, so using only the message from the oldest limits the usefulness of this feature, but I guess for certain people the bottommost commit would be a good default.
I see you have already an option to grab messages from all the commits in the range (many of which may have useless "oops, that was wrong" single-liner) in a way similar to how "git rebase --squash" or "squash" insn in the "git rebase -i" todo list lets you use them in the next step, which is workable. It is plausible that we would later want to offer an option to name the single commit that may not be the bottommost one and use the message only from that commit.
But we'd need to start from somewhere, and "use the bottommost commit and nothing else" and "we will give you messages from all the commits, just rearrange them in your editor" may be a good place to start.
As t3454 is taken by another topic already in flight, I've queued a trivial "rename it to t3455" patch on top before queuing the topic.
Thanks.