From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Phillip Wood <phillip.wood123@gmail.com>,
"D. Ben Knoble" <ben.knoble@gmail.com>,
Patrick Steinhardt <ps@pks.im>, Matt Hunter <m@lfurio.us>,
Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v13 4/8] history: add skeleton for squash subcommand
Date: Fri, 07 Aug 2026 07:39:27 +0000 [thread overview]
Message-ID: <f7d953b081ed312770dd03d827114bb3156195b8.1786088371.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2337.v13.git.git.1786088371.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>
Add the entry point and option parsing for "git history squash". Pass
the remaining arguments through setup_revisions() so the command accepts
revision ranges and rev-list options, while restoring the ordering and
simplification settings required by the fold if an option changes them.
Require at least one BOTTOM revision. The squashed commit needs a commit
outside the selected range to serve as its base, so a single positive
revision is not a sufficient range.
Keep this step limited to defining the revision input contract so graph
validation and the rewrite can be added independently.
Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
Documentation/git-history.adoc | 1 +
builtin/history.c | 94 ++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
diff --git a/Documentation/git-history.adoc b/Documentation/git-history.adoc
index 28b477cd37..b660baf94d 100644
--- a/Documentation/git-history.adoc
+++ b/Documentation/git-history.adoc
@@ -12,6 +12,7 @@ git history drop <commit> [--dry-run] [--update-refs=(branches|head)] [--empty=(
git history fixup <commit> [--dry-run] [--update-refs=(branches|head)] [--reedit-message] [--empty=(drop|keep|abort)]
git history reword <commit> [--dry-run] [--update-refs=(branches|head)]
git history split <commit> [--dry-run] [--update-refs=(branches|head)] [--] [<pathspec>...]
+git history squash [--dry-run] [--update-refs=(branches|head)] [--[no-]edit] <revision-range>
DESCRIPTION
-----------
diff --git a/builtin/history.c b/builtin/history.c
index a60e8dbcd0..4f5a7a46ce 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -34,6 +34,8 @@
N_("git history reword <commit> [--dry-run] [--update-refs=(branches|head)]")
#define GIT_HISTORY_SPLIT_USAGE \
N_("git history split <commit> [--dry-run] [--update-refs=(branches|head)] [--] [<pathspec>...]")
+#define GIT_HISTORY_SQUASH_USAGE \
+ N_("git history squash [--dry-run] [--update-refs=(branches|head)] [--[no-]edit] <revision-range>")
static void change_data_free(void *util, const char *str UNUSED)
{
@@ -1004,6 +1006,96 @@ out:
return ret;
}
+static int setup_squash_revisions(struct repository *repo,
+ int argc, const char **argv,
+ struct rev_info *revs)
+{
+ repo_init_revisions(repo, revs, NULL);
+ revs->reverse = 1;
+ revs->topo_order = 1;
+ revs->sort_order = REV_SORT_IN_GRAPH_ORDER;
+ revs->simplify_history = 0;
+ revs->ancestry_path = 1;
+ revs->limited = 1;
+ revs->ancestry_path_implicit_bottoms = 1;
+
+ argc = setup_revisions(argc, argv, revs, NULL);
+ if (argc > 1)
+ return error(_("unrecognized argument: %s"), argv[1]);
+
+ if (revs->reverse != 1 || revs->topo_order != 1 ||
+ revs->sort_order != REV_SORT_IN_GRAPH_ORDER ||
+ revs->simplify_history != 0 || revs->boundary == 1 ||
+ revs->ancestry_path != 1 || revs->limited != 1 ||
+ revs->ancestry_path_implicit_bottoms != 1) {
+ warning(_("ignoring rev-list options that would change how the "
+ "range is walked"));
+ revs->reverse = 1;
+ revs->topo_order = 1;
+ revs->sort_order = REV_SORT_IN_GRAPH_ORDER;
+ revs->simplify_history = 0;
+ revs->boundary = 0;
+ revs->ancestry_path = 1;
+ revs->limited = 1;
+ revs->ancestry_path_implicit_bottoms = 1;
+ }
+
+ /*
+ * A squash needs a base to reparent onto, so the range has to exclude
+ * something, as in "<base>..<tip>". A revision range with no such
+ * bottom commit cannot be squashed.
+ */
+ for (size_t i = 0; i < revs->cmdline.nr; i++)
+ if (revs->cmdline.rev[i].flags & BOTTOM)
+ return 0;
+
+ return error(_("not a '<base>..<tip>' revision range"));
+}
+
+static int cmd_history_squash(int argc,
+ const char **argv,
+ const char *prefix,
+ struct repository *repo)
+{
+ const char * const usage[] = {
+ GIT_HISTORY_SQUASH_USAGE,
+ NULL,
+ };
+ enum ref_action action = REF_ACTION_DEFAULT;
+ int dry_run = 0;
+ int edit = 1;
+ struct option options[] = {
+ OPT_CALLBACK_F(0, "update-refs", &action, "(branches|head)",
+ N_("control which refs should be updated"),
+ PARSE_OPT_NONEG, parse_ref_action),
+ OPT_BOOL('n', "dry-run", &dry_run,
+ N_("perform a dry-run without updating any refs")),
+ OPT_BOOL('e', "edit", &edit,
+ N_("edit the commit message")),
+ OPT_END(),
+ };
+ struct rev_info revs = { 0 };
+ int ret;
+
+ argc = parse_options(argc, argv, prefix, options, usage,
+ PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_KEEP_ARGV0);
+ if (argc < 2) {
+ ret = error(_("command expects a revision range"));
+ goto out;
+ }
+ repo_config(repo, git_default_config, NULL);
+
+ ret = setup_squash_revisions(repo, argc, argv, &revs);
+ if (ret < 0)
+ goto out;
+
+ ret = error(_("squashing commits is not implemented yet"));
+
+out:
+ release_revisions(&revs);
+ return ret;
+}
+
static int update_worktree(struct repository *repo,
const struct commit *old_head,
const struct commit *new_head,
@@ -1192,6 +1284,7 @@ int cmd_history(int argc,
GIT_HISTORY_FIXUP_USAGE,
GIT_HISTORY_REWORD_USAGE,
GIT_HISTORY_SPLIT_USAGE,
+ GIT_HISTORY_SQUASH_USAGE,
NULL,
};
parse_opt_subcommand_fn *fn = NULL;
@@ -1200,6 +1293,7 @@ int cmd_history(int argc,
OPT_SUBCOMMAND("fixup", &fn, cmd_history_fixup),
OPT_SUBCOMMAND("reword", &fn, cmd_history_reword),
OPT_SUBCOMMAND("split", &fn, cmd_history_split),
+ OPT_SUBCOMMAND("squash", &fn, cmd_history_squash),
OPT_END(),
};
--
gitgitgadget
next prev parent reply other threads:[~2026-08-07 7:39 UTC|newest]
Thread overview: 152+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-14 19:25 [PATCH 0/2] rebase: add --fixup to fold a range into its oldest commit Harald Nordgren via GitGitGadget
2026-06-14 19:25 ` [PATCH 1/2] t3415: remove prepare-commit-msg hook after use Harald Nordgren via GitGitGadget
2026-06-14 19:25 ` [PATCH 2/2] rebase: add --fixup-all to fold a range Harald Nordgren via GitGitGadget
2026-06-15 2:01 ` [PATCH 0/2] rebase: add --fixup to fold a range into its oldest commit Junio C Hamano
2026-06-15 8:18 ` Harald Nordgren
2026-06-15 15:17 ` D. Ben Knoble
2026-06-16 8:34 ` Patrick Steinhardt
2026-06-17 9:30 ` Harald Nordgren
2026-06-15 8:37 ` [PATCH v2 0/2] rebase: add --squash to fold a range into its first commit Harald Nordgren via GitGitGadget
2026-06-15 8:37 ` [PATCH v2 1/2] t3415: remove prepare-commit-msg hook after use Harald Nordgren via GitGitGadget
2026-06-15 8:37 ` [PATCH v2 2/2] rebase: add --squash to fold a range Harald Nordgren via GitGitGadget
2026-06-16 10:10 ` [PATCH v2 0/2] rebase: add --squash to fold a range into its first commit Phillip Wood
2026-06-17 9:11 ` Harald Nordgren
2026-06-17 9:48 ` Phillip Wood
2026-06-18 19:17 ` [PATCH v3 0/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-06-18 19:17 ` [PATCH v3 1/4] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-06-18 19:17 ` [PATCH v3 2/4] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-06-18 19:17 ` [PATCH v3 3/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-06-18 20:30 ` Junio C Hamano
2026-06-18 21:24 ` Junio C Hamano
2026-06-18 21:29 ` D. Ben Knoble
2026-06-19 12:55 ` Patrick Steinhardt
2026-06-18 19:17 ` [PATCH v3 4/4] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-06-18 21:23 ` [PATCH v3 0/4] history: add squash subcommand to fold a range D. Ben Knoble
2026-06-19 0:34 ` Junio C Hamano
2026-06-19 12:37 ` Patrick Steinhardt
2026-06-19 16:11 ` Junio C Hamano
2026-06-21 5:53 ` [PATCH v4 " Harald Nordgren via GitGitGadget
2026-06-21 5:53 ` [PATCH v4 1/4] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-06-21 5:53 ` [PATCH v4 2/4] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-06-21 5:53 ` [PATCH v4 3/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-06-21 5:53 ` [PATCH v4 4/4] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-06-22 11:54 ` [PATCH v4 0/4] history: add squash subcommand to fold a range Patrick Steinhardt
2026-06-23 10:41 ` Harald Nordgren
2026-06-24 21:54 ` [PATCH v5 " Harald Nordgren via GitGitGadget
2026-06-24 21:54 ` [PATCH v5 1/4] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-06-24 21:55 ` [PATCH v5 2/4] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-06-24 21:55 ` [PATCH v5 3/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-06-24 21:55 ` [PATCH v5 4/4] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-06-26 8:52 ` [PATCH v5 0/4] history: add squash subcommand to fold a range Phillip Wood
2026-06-26 9:57 ` Harald Nordgren
2026-06-26 13:12 ` Phillip Wood
2026-06-26 14:02 ` Junio C Hamano
2026-06-26 18:36 ` Harald Nordgren
2026-06-29 6:26 ` Patrick Steinhardt
2026-06-29 15:51 ` Phillip Wood
2026-06-29 16:54 ` Junio C Hamano
2026-07-01 13:45 ` Phillip Wood
2026-06-29 18:03 ` Harald Nordgren
2026-06-29 19:48 ` Phillip Wood
2026-06-29 21:13 ` Harald Nordgren
2026-06-30 13:48 ` Phillip Wood
2026-06-30 18:38 ` Harald Nordgren
2026-07-01 10:31 ` Phillip Wood
2026-07-01 13:47 ` Junio C Hamano
2026-07-01 15:14 ` Phillip Wood
2026-07-01 17:41 ` Junio C Hamano
2026-07-02 13:58 ` Phillip Wood
2026-06-30 2:55 ` Matt Hunter
2026-06-30 7:19 ` Harald Nordgren
2026-06-30 9:23 ` Matt Hunter
2026-06-30 14:01 ` Phillip Wood
2026-07-02 12:54 ` Patrick Steinhardt
2026-07-02 20:28 ` Junio C Hamano
2026-06-29 16:09 ` Harald Nordgren
2026-06-28 8:29 ` [PATCH v6 " Harald Nordgren via GitGitGadget
2026-06-28 8:29 ` [PATCH v6 1/4] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-06-28 8:29 ` [PATCH v6 2/4] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-06-28 8:29 ` [PATCH v6 3/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-06-29 5:50 ` Junio C Hamano
2026-06-28 8:29 ` [PATCH v6 4/4] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-06-29 5:50 ` Junio C Hamano
2026-06-29 13:49 ` Harald Nordgren
2026-06-29 14:49 ` Junio C Hamano
2026-06-29 17:38 ` Junio C Hamano
2026-07-06 8:50 ` [PATCH v7 0/5] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-07-06 8:50 ` [PATCH v7 1/5] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-07-06 8:50 ` [PATCH v7 2/5] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-07-06 8:50 ` [PATCH v7 3/5] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-07-06 8:50 ` [PATCH v7 4/5] sequencer: extract helpers for the squash message markers Harald Nordgren via GitGitGadget
2026-07-06 8:50 ` [PATCH v7 5/5] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-07-06 14:06 ` [PATCH v7 0/5] history: add squash subcommand to fold a range Phillip Wood
2026-07-07 7:51 ` Harald Nordgren
2026-07-07 8:55 ` Harald Nordgren
2026-07-07 9:30 ` Phillip Wood
2026-07-07 9:48 ` Phillip Wood
2026-07-06 20:42 ` Junio C Hamano
2026-07-10 9:06 ` [PATCH v8 " Harald Nordgren via GitGitGadget
2026-07-10 9:06 ` [PATCH v8 1/5] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-07-10 9:06 ` [PATCH v8 2/5] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-07-10 9:06 ` [PATCH v8 3/5] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-07-10 9:06 ` [PATCH v8 4/5] sequencer: share the squash message marker helpers and flags Harald Nordgren via GitGitGadget
2026-07-10 9:06 ` [PATCH v8 5/5] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-07-14 4:44 ` [PATCH v8 0/5] history: add squash subcommand to fold a range Matt Hunter
2026-07-14 8:38 ` Harald Nordgren
2026-07-14 9:04 ` Harald Nordgren
2026-07-14 12:36 ` Ben Knoble
2026-07-14 18:41 ` Junio C Hamano
2026-07-15 15:16 ` [PATCH v9 " Harald Nordgren via GitGitGadget
2026-07-15 15:16 ` [PATCH v9 1/5] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-07-15 15:16 ` [PATCH v9 2/5] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-07-15 15:16 ` [PATCH v9 3/5] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-07-18 8:52 ` Matt Hunter
2026-07-18 9:28 ` Harald Nordgren
2026-07-15 15:16 ` [PATCH v9 4/5] sequencer: share the squash message marker helpers and flags Harald Nordgren via GitGitGadget
2026-07-15 15:16 ` [PATCH v9 5/5] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-07-18 8:52 ` Matt Hunter
2026-07-18 9:36 ` Harald Nordgren
2026-07-20 8:26 ` [PATCH v10 0/5] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-07-20 8:27 ` [PATCH v10 1/5] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-07-20 8:27 ` [PATCH v10 2/5] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-07-20 8:27 ` [PATCH v10 3/5] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-08-03 9:49 ` Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.1/3.7] fixup! " Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.2/3.7] " Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.3/3.7] " Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.4/3.7] " Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.5/3.7] " Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.6/3.7] " Phillip Wood
2026-08-03 9:49 ` [PATCH v10 3.7/3.7] " Phillip Wood
2026-08-03 16:35 ` [PATCH v10 3/5] " Harald Nordgren
2026-08-04 9:36 ` Phillip Wood
2026-08-04 13:21 ` Junio C Hamano
2026-08-04 20:41 ` Harald Nordgren
2026-08-04 20:50 ` Harald Nordgren
2026-08-07 14:32 ` Tuomas Ahola
2026-08-04 21:12 ` Junio C Hamano
2026-08-07 13:47 ` Phillip Wood
2026-08-07 18:31 ` Harald Nordgren
2026-08-06 9:19 ` Kristoffer Haugsbakk
2026-07-20 8:27 ` [PATCH v10 4/5] sequencer: share the squash message marker helpers and flags Harald Nordgren via GitGitGadget
2026-07-20 8:27 ` [PATCH v10 5/5] history: re-edit a squash with every message Harald Nordgren via GitGitGadget
2026-07-21 1:33 ` [PATCH v10 0/5] history: add squash subcommand to fold a range Matt Hunter
2026-08-01 6:53 ` [PATCH v11 0/4] " Harald Nordgren via GitGitGadget
2026-08-01 6:53 ` [PATCH v11 1/4] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-08-01 6:53 ` [PATCH v11 2/4] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-08-01 6:53 ` [PATCH v11 3/4] sequencer: share the squash message marker helpers and flags Harald Nordgren via GitGitGadget
2026-08-01 6:53 ` [PATCH v11 4/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-08-04 8:30 ` [PATCH v12 0/4] " Harald Nordgren via GitGitGadget
2026-08-04 8:30 ` [PATCH v12 1/4] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-08-04 8:30 ` [PATCH v12 2/4] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-08-04 8:30 ` [PATCH v12 3/4] sequencer: share the squash message marker helpers and flags Harald Nordgren via GitGitGadget
2026-08-04 8:30 ` [PATCH v12 4/4] history: add squash subcommand to fold a range Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 0/8] " Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 1/8] history: extract helper for a commit's parent tree Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 2/8] history: give commit_tree_ext a message template Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 3/8] sequencer: share the squash message marker helpers and flags Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` Harald Nordgren via GitGitGadget [this message]
2026-08-07 7:39 ` [PATCH v13 5/8] history: validate squash revision ranges Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 6/8] history: protect branches when squashing a range Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 7/8] history: create squashed commits without editing Harald Nordgren via GitGitGadget
2026-08-07 7:39 ` [PATCH v13 8/8] history: support editing squashed commit messages Harald Nordgren via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f7d953b081ed312770dd03d827114bb3156195b8.1786088371.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@gmail.com \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=m@lfurio.us \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox