From: Patrick Steinhardt Date: Thu, 11 Jun 2026 13:27:03 GMT Subject: [PATCH v5 00/10] builtin/history: introduce "drop" subcommand Message-ID: <20260611-b4-pks-history-drop-v5-0-34d35725559c@pks.im> In-Reply-To: <20260601-b4-pks-history-drop-v1-0-643e32340d55@pks.im> Hi, this small patch series introduces the new "drop" subcommand for git-history(1). As a reader might guess, the command does exactly that: given a commit, it will drop that commit from the commit history and replay descendant branches on top of it. Changes in v5: - Reject UPDATE_ORIG_HEAD without UPDATE_HEAD. - Link to v4: https://patch.msgid.link/20260610-b4-pks-history-drop-v4-0-70d5f0ae8c25@pks.im Changes in v4: - Remove the `SKIP_REF_UPDATES` flag in favor of a new `UPDATE_HEAD` flag, as suggested by Phillip. - Rename `reset_head()` to `reset_working_tree()`. This better matches the new scope of the function, and it helps us to catch any in-flight patches that would now have to set the `UPDATE_HEAD` flag. - Link to v3: https://patch.msgid.link/20260608-b4-pks-history-drop-v3-0-84ca8e43e937@pks.im Changes in v3: - Fix commit message typos. - Make `update_orig_head` and `skip_ref_updates` mutually exclusive. - Use fancy revisions to specify the commit to drop in the example section. - Detect conflicting changes in the index/working tree in dry-run mode. - Consistently use a subshell. - Rename `RESET_HEAD_ORIG_HEAD` to `RESET_HEAD_UPDATE_ORIG_HEAD`. - - Link to v2: https://patch.msgid.link/20260603-b4-pks-history-drop-v2-0-742cb5b5176d@pks.im Changes in v2: - Reworked `update_worktree()` to use `reset_head()`, which required a bunch of changes to `reset_head()`. - Consistently mention the commit that cannot be dropped as part of error messages. - Adapt error message to not use backticks anymore. - Drop redundant "--graph" flag in a test helper. - Link to v1: https://patch.msgid.link/20260601-b4-pks-history-drop-v1-0-643e32340d55@pks.im Thanks! Patrick --- Patrick Steinhardt (10): read-cache: split out function to drop unmerged entries to stage 0 reset: drop `USE_THE_REPOSITORY_VARIABLE` reset: rename `reset_head()` reset: modernize flags passed to `reset_working_tree()` reset: introduce dry-run mode reset: introduce ability to skip updating HEAD reset: allow the caller to specify the current HEAD object reset: stop assuming that the caller passes in a clean index builtin/history: split handling of ref updates into two phases builtin/history: implement "drop" subcommand Documentation/git-history.adoc | 38 ++- builtin/history.c | 288 +++++++++++++++++++--- builtin/rebase.c | 41 ++-- read-cache-ll.h | 1 + read-cache.c | 12 +- reset.c | 102 +++++--- reset.h | 51 ++-- sequencer.c | 17 +- t/meson.build | 1 + t/t3454-history-drop.sh | 537 +++++++++++++++++++++++++++++++++++++++++ 10 files changed, 971 insertions(+), 117 deletions(-) Range-diff versus v4: 1: 82e26ff318 = 1: 6f74de2025 read-cache: split out function to drop unmerged entries to stage 0 2: 93e6e7276c = 2: 673658d03c reset: drop `USE_THE_REPOSITORY_VARIABLE` 3: 79c2877a65 = 3: 3a4745775a reset: rename `reset_head()` 4: 9e67c7ee84 = 4: d53df7446e reset: modernize flags passed to `reset_working_tree()` 5: 4da39e7cec = 5: 2c06054013 reset: introduce dry-run mode 6: 683897ac8d ! 6: b9f3438140 reset: introduce ability to skip updating HEAD @@ reset.c: int reset_working_tree(struct repository *r, unsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD; unsigned dry_run = opts->flags & RESET_WORKING_TREE_DRY_RUN; struct object_id *head = NULL, head_oid; +@@ reset.c: int reset_working_tree(struct repository *r, + if (opts->branch_msg && !opts->branch) + BUG("branch reflog message given without a branch"); + ++ if (update_orig_head && !update_head) ++ BUG("cannot update ORIG_HEAD without updating HEAD" ); ++ + if (!refs_only && !dry_run && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { + ret = -1; + goto leave_reset_head; @@ reset.c: int reset_working_tree(struct repository *r, oid = &head_oid; 7: 2d70838562 = 7: 9e7af4b77b reset: allow the caller to specify the current HEAD object 8: ad56a2d370 = 8: 90b12199e8 reset: stop assuming that the caller passes in a clean index 9: b47f608e92 = 9: a7e0e345be builtin/history: split handling of ref updates into two phases 10: f39ec74b0f = 10: 93bc3d46a4 builtin/history: implement "drop" subcommand --- base-commit: 1666c1265231b0bc5f613fbbf3f0a9896cdef76e change-id: 20260601-b4-pks-history-drop-28f6c6399e7b