git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 00/10] builtin/history: introduce "drop" subcommand

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 10, 2026, 08:52 UTC
Message-ID
<20260610-b4-pks-history-drop-v4-0-70d5f0ae8c25@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 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                        |  99 +++++---
 reset.h                        |  51 ++--
 sequencer.c                    |  17 +-
 t/meson.build                  |   1 +
 t/t3454-history-drop.sh        | 537 +++++++++++++++++++++++++++++++++++++++++
 10 files changed, 968 insertions(+), 117 deletions(-)
Range-diff versus v3:
 1:  e9291b8592 =  1:  63c1a10ca0 read-cache: split out function to drop unmerged entries to stage 0
 2:  6ae06725ca =  2:  b83e2124e8 reset: drop `USE_THE_REPOSITORY_VARIABLE`
 3:  53bf10c527 <  -:  ---------- reset: modernize flags passed to `reset_head()`
 -:  ---------- >  3:  0488effe71 reset: rename `reset_head()`
 -:  ---------- >  4:  364e71ee9c reset: modernize flags passed to `reset_working_tree()`
 4:  b8e5464d06 !  5:  0fa45bd263 reset: introduce dry-run mode
    @@ Metadata
      ## Commit message ##
         reset: introduce dry-run mode
     
    -    In a subsequent commit we'll add another caller to `reset_head()` that
    -    wants to perform a dry-run check of whether it would be possible to
    +    In a subsequent commit we'll add another caller to `reset_working_tree()`
    +    that wants to perform a dry-run check of whether it would be possible to
         update the index and working tree when moving to a new commit. Introduce
         a new flag that lets the caller perform this operation.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
      ## reset.c ##
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    - 	unsigned reset_hard = opts->flags & RESET_HEAD_HARD;
    - 	unsigned refs_only = opts->flags & RESET_HEAD_REFS_ONLY;
    - 	unsigned update_orig_head = opts->flags & RESET_HEAD_UPDATE_ORIG_HEAD;
    -+	unsigned dry_run = opts->flags & RESET_HEAD_DRY_RUN;
    +@@ reset.c: int reset_working_tree(struct repository *r,
    + 	unsigned reset_hard = opts->flags & RESET_WORKING_TREE_HARD;
    + 	unsigned refs_only = opts->flags & RESET_WORKING_TREE_REFS_ONLY;
    + 	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;
      	struct tree_desc desc[2] = { { NULL }, { NULL } };
      	struct lock_file lock = LOCK_INIT;
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      	const char *action;
      	int ret = 0, nr = 0;
      
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      	if (opts->branch_msg && !opts->branch)
      		BUG("branch reflog message given without a branch");
      
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      		ret = -1;
      		goto leave_reset_head;
      	}
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      	if (!oid)
      		oid = &head_oid;
      
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      	unpack_tree_opts.merge = 1;
      	unpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
      	unpack_tree_opts.skip_cache_tree_update = 1;
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      	if (reset_hard)
      		unpack_tree_opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;
      
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      	if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) {
      		ret = error(_("failed to find tree of %s"),
      			    oid_to_hex(&head_oid));
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      		goto leave_reset_head;
      	}
      
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      	tree = repo_parse_tree_indirect(r, oid);
      	if (!tree) {
      		ret = error(_("unable to read tree (%s)"), oid_to_hex(oid));
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      leave_reset_head:
      	rollback_lock_file(&lock);
      	clear_unpack_trees_porcelain(&unpack_tree_opts);
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      	return ret;
     
      ## reset.h ##
    -@@ reset.h: enum reset_head_flags {
    +@@ reset.h: enum reset_working_tree_flags {
      
      	/* Update ORIG_HEAD as well as HEAD */
    - 	RESET_HEAD_UPDATE_ORIG_HEAD = (1 << 4),
    + 	RESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 4),
     +
     +	/*
     +	 * Perform a dry-run by performing the operation without updating
     +	 * any user-visible state.
     +	 */
    -+	RESET_HEAD_DRY_RUN = (1 << 5),
    ++	RESET_WORKING_TREE_DRY_RUN = (1 << 5),
      };
      
    - struct reset_head_opts {
    + struct reset_working_tree_options {
 5:  bbb8b98f8e <  -:  ---------- reset: introduce ability to skip reference updates
 -:  ---------- >  6:  4f844adaa7 reset: introduce ability to skip updating HEAD
 6:  24cccf728f !  7:  28e7dd039e reset: allow the caller to specify the current HEAD object
    @@ Metadata
      ## Commit message ##
         reset: allow the caller to specify the current HEAD object
     
    -    When calling `reset_head()` we automatically derive the commit that the
    -    callers wants to move from by reading the HEAD commit. Some callers may
    -    already have resolved it, or they may want to move from a different
    -    commit that doesn't match HEAD.
    +    When calling `reset_working_tree()` we automatically derive the commit
    +    that the callers wants to move from by reading the HEAD commit. Some
    +    callers may already have resolved it, or they may want to move from a
    +    different commit that doesn't match HEAD.
     
         Introduce a new `oid_from` option that lets the caller specify the
         commit.
    @@ Commit message
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
      ## reset.c ##
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      		goto leave_reset_head;
      	}
      
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      		ret = error(_("could not determine HEAD revision"));
     
      ## reset.h ##
    -@@ reset.h: struct reset_head_opts {
    +@@ reset.h: struct reset_working_tree_options {
      	 * The commit to checkout/reset to. Defaults to HEAD.
      	 */
      	const struct object_id *oid;
 7:  4b79437a50 !  8:  6b590da34e reset: stop assuming that the caller passes in a clean index
    @@ Commit message
         reset: stop assuming that the caller passes in a clean index
     
         In 652bd0211d (rebase: use 'skip_cache_tree_update' option, 2022-11-10),
    -    we updated `reset_head()` to stop updating the index tree cache. This
    -    was done as a performance optimization: the function is only called by
    -    "sequencer.c" and "rebase.c", both of which assume a clean index before
    -    they perform their operation, so we know that the end result will be a
    -    clean index, too. Consequently, we can skip recomputing the cache as we
    -    can instead use `prime_cache_tree()` directly.
    +    we updated `reset_working_tree()` to stop updating the index tree cache.
    +    This was done as a performance optimization: the function is only called
    +    by "sequencer.c" and "rebase.c", both of which assume a clean index
    +    before they perform their operation, so we know that the end result will
    +    be a clean index, too. Consequently, we can skip recomputing the cache
    +    as we can instead use `prime_cache_tree()` directly.
     
         In a subsequent commit we're about to add a new caller though where the
         assumption doesn't hold anymore: the index may be dirty before calling
    -    `reset_head()`, and consequently we cannot prime the cache with a given
    -    tree anymore as the index and tree will mismatch.
    +    `reset_working_tree()`, and consequently we cannot prime the cache with
    +    a given tree anymore as the index and tree will mismatch.
     
         Adapt the logic so that we only skip the cache tree update in case we're
         doing a hard reset. While we could introduce logic that only skips the
    @@ Commit message
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
      ## reset.c ##
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      	unpack_tree_opts.dry_run = dry_run;
      	unpack_tree_opts.merge = 1;
      	unpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
    @@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts
      
      	if (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) {
      		ret = error(_("failed to find tree of %s"),
    -@@ reset.c: int reset_head(struct repository *r, const struct reset_head_opts *opts)
    +@@ reset.c: int reset_working_tree(struct repository *r,
      		goto leave_reset_head;
      	}
      
 8:  d01c7ffb29 =  9:  fddadbf87f builtin/history: split handling of ref updates into two phases
 9:  c75925f7ed ! 10:  cb09216db3 builtin/history: implement "drop" subcommand
    @@ builtin/history.c: static int cmd_history_split(int argc,
     +			   const struct commit *new_head,
     +			   bool dry_run)
     +{
    -+	struct reset_head_opts opts = {
    ++	struct reset_working_tree_options opts = {
     +		.oid_from = &old_head->object.oid,
     +		.oid = &new_head->object.oid,
    -+		.flags = RESET_HEAD_SKIP_REF_UPDATES,
     +	};
     +	if (dry_run)
    -+		opts.flags |= RESET_HEAD_DRY_RUN;
    -+	return reset_head(repo, &opts);
    ++		opts.flags |= RESET_WORKING_TREE_DRY_RUN;
    ++	return reset_working_tree(repo, &opts);
     +}
     +
     +static int find_head_tree_change(struct repository *repo,

--- base-commit: 1666c1265231b0bc5f613fbbf3f0a9896cdef76e change-id: 20260601-b4-pks-history-drop-28f6c6399e7b

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 44 of 101 in “builtin/history: introduce "drop" subcommand”
  1. 0/2 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 1, 2026
  2. 1/2 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 1, 2026
  3. 2/2 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 1, 2026
  4. Junio C HamanoJun 1, 2026
  5. Patrick SteinhardtJun 3, 2026
  6. Pablo SabaterJun 2, 2026
  7. Patrick SteinhardtJun 3, 2026
  8. 0/9 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 3, 2026
  9. 1/9 read-cache: split out function to drop unmerged entries to stage 0Patrick Steinhardt, Jun 3, 2026
  10. 2/9 reset: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jun 3, 2026
  11. 3/9 reset: modernize flags passed to `reset_head()`Patrick Steinhardt, Jun 3, 2026
  12. Kristoffer HaugsbakkJun 3, 2026
  13. Phillip WoodJun 5, 2026
  14. Patrick SteinhardtJun 8, 2026
  15. 4/9 reset: introduce dry-run modePatrick Steinhardt, Jun 3, 2026
  16. Kristoffer HaugsbakkJun 3, 2026
  17. Junio C HamanoJun 3, 2026
  18. 5/9 reset: introduce ability to skip reference updatesPatrick Steinhardt, Jun 3, 2026
  19. Junio C HamanoJun 3, 2026
  20. Patrick SteinhardtJun 4, 2026
  21. Phillip WoodJun 5, 2026
  22. Patrick SteinhardtJun 8, 2026
  23. Patrick SteinhardtJun 8, 2026
  24. Phillip WoodJun 9, 2026
  25. Patrick SteinhardtJun 10, 2026
  26. 6/9 reset: allow the caller to specify the current HEAD objectPatrick Steinhardt, Jun 3, 2026
  27. 7/9 reset: stop assuming that the caller passes in a clean indexPatrick Steinhardt, Jun 3, 2026
  28. 8/9 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 3, 2026
  29. 9/9 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 3, 2026
  30. Kristoffer HaugsbakkJun 3, 2026
  31. Patrick SteinhardtJun 4, 2026
  32. Junio C HamanoJun 3, 2026
  33. Patrick SteinhardtJun 4, 2026
  34. 0/9 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 8, 2026
  35. 1/9 read-cache: split out function to drop unmerged entries to stage 0Patrick Steinhardt, Jun 8, 2026
  36. 2/9 reset: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jun 8, 2026
  37. 3/9 reset: modernize flags passed to `reset_head()`Patrick Steinhardt, Jun 8, 2026
  38. 4/9 reset: introduce dry-run modePatrick Steinhardt, Jun 8, 2026
  39. 5/9 reset: introduce ability to skip reference updatesPatrick Steinhardt, Jun 8, 2026
  40. 6/9 reset: allow the caller to specify the current HEAD objectPatrick Steinhardt, Jun 8, 2026
  41. 7/9 reset: stop assuming that the caller passes in a clean indexPatrick Steinhardt, Jun 8, 2026
  42. 8/9 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 8, 2026
  43. 9/9 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 8, 2026
  44. 00/10 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 10, 2026
  45. 01/10 read-cache: split out function to drop unmerged entries to stage 0Patrick Steinhardt, Jun 10, 2026
  46. 02/10 reset: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jun 10, 2026
  47. 03/10 reset: rename `reset_head()`Patrick Steinhardt, Jun 10, 2026
  48. Phillip WoodJun 10, 2026
  49. 04/10 reset: modernize flags passed to `reset_working_tree()`Patrick Steinhardt, Jun 10, 2026
  50. Phillip WoodJun 10, 2026
  51. 05/10 reset: introduce dry-run modePatrick Steinhardt, Jun 10, 2026
  52. 06/10 reset: introduce ability to skip updating HEADPatrick Steinhardt, Jun 10, 2026
  53. Phillip WoodJun 10, 2026
  54. Patrick SteinhardtJun 11, 2026
  55. 07/10 reset: allow the caller to specify the current HEAD objectPatrick Steinhardt, Jun 10, 2026
  56. 08/10 reset: stop assuming that the caller passes in a clean indexPatrick Steinhardt, Jun 10, 2026
  57. 09/10 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 10, 2026
  58. Junio C HamanoJun 10, 2026
  59. 10/10 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 10, 2026
  60. 00/10 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 11, 2026
  61. 01/10 read-cache: split out function to drop unmerged entries to stage 0Patrick Steinhardt, Jun 11, 2026
  62. 02/10 reset: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jun 11, 2026
  63. 03/10 reset: rename `reset_head()`Patrick Steinhardt, Jun 11, 2026
  64. 04/10 reset: modernize flags passed to `reset_working_tree()`Patrick Steinhardt, Jun 11, 2026
  65. 05/10 reset: introduce dry-run modePatrick Steinhardt, Jun 11, 2026
  66. 06/10 reset: introduce ability to skip updating HEADPatrick Steinhardt, Jun 11, 2026
  67. Junio C HamanoJun 11, 2026
  68. Patrick SteinhardtJun 15, 2026
  69. 07/10 reset: allow the caller to specify the current HEAD objectPatrick Steinhardt, Jun 11, 2026
  70. 08/10 reset: stop assuming that the caller passes in a clean indexPatrick Steinhardt, Jun 11, 2026
  71. 09/10 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 11, 2026
  72. 10/10 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 11, 2026
  73. 00/10 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 15, 2026
  74. 01/10 read-cache: split out function to drop unmerged entries to stage 0Patrick Steinhardt, Jun 15, 2026
  75. 02/10 reset: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jun 15, 2026
  76. 03/10 reset: rename `reset_head()`Patrick Steinhardt, Jun 15, 2026
  77. 04/10 reset: modernize flags passed to `reset_working_tree()`Patrick Steinhardt, Jun 15, 2026
  78. 05/10 reset: introduce dry-run modePatrick Steinhardt, Jun 15, 2026
  79. 06/10 reset: introduce ability to skip updating HEADPatrick Steinhardt, Jun 15, 2026
  80. 07/10 reset: allow the caller to specify the current HEAD objectPatrick Steinhardt, Jun 15, 2026
  81. 08/10 reset: stop assuming that the caller passes in a clean indexPatrick Steinhardt, Jun 15, 2026
  82. 09/10 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 15, 2026
  83. Christian CouderJun 25, 2026
  84. Patrick SteinhardtJun 29, 2026
  85. 10/10 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 15, 2026
  86. Christian CouderJun 25, 2026
  87. Junio C HamanoJun 25, 2026
  88. 00/11 builtin/history: introduce "drop" subcommandPatrick Steinhardt, Jun 29, 2026
  89. 01/11 read-cache: split out function to drop unmerged entries to stage 0Patrick Steinhardt, Jun 29, 2026
  90. 02/11 reset: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jun 29, 2026
  91. 03/11 reset: rename `reset_head()`Patrick Steinhardt, Jun 29, 2026
  92. 04/11 reset: modernize flags passed to `reset_working_tree()`Patrick Steinhardt, Jun 29, 2026
  93. 05/11 reset: introduce dry-run modePatrick Steinhardt, Jun 29, 2026
  94. 06/11 reset: introduce ability to skip updating HEADPatrick Steinhardt, Jun 29, 2026
  95. 07/11 reset: allow the caller to specify the current HEAD objectPatrick Steinhardt, Jun 29, 2026
  96. 08/11 reset: stop assuming that the caller passes in a clean indexPatrick Steinhardt, Jun 29, 2026
  97. 09/11 replay: expose `replay_result_queue_update()`Patrick Steinhardt, Jun 29, 2026
  98. 10/11 builtin/history: split handling of ref updates into two phasesPatrick Steinhardt, Jun 29, 2026
  99. 11/11 builtin/history: implement "drop" subcommandPatrick Steinhardt, Jun 29, 2026
  100. Junio C HamanoJun 29, 2026
  101. Patrick SteinhardtJul 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.