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

Re: [PATCH v2 9/9] builtin/history: implement "drop" subcommand

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 4, 2026, 09:02 UTC
Message-ID
<aiE_D9Dzryfx8iQI@pks.im>
In-Reply-To
<4b4672de-17cc-426f-8498-6384b1ad0d06@app.fastmail.com>
On Wed, Jun 03, 2026 at 09:04:33PM +0200, Kristoffer Haugsbakk wrote:
Show 31 quoted lines
> On Wed, Jun 3, 2026, at 18:14, Patrick Steinhardt wrote:
> > diff --git a/Documentation/git-history.adoc
> > b/Documentation/git-history.adoc
> > index 2ba8121795..4eac732fd2 100644
> > --- a/Documentation/git-history.adoc
> > +++ b/Documentation/git-history.adoc
> > @@ -51,13 +52,28 @@ be stateful operations. The limitation can be
> > lifted once (if) Git learns about
> >  first-class conflicts.
> >
> >  When using `fixup` with `--empty=drop`, dropping the root commit is not yet
> > -supported.
> > +supported. Likewise, `drop` cannot remove the root commit or a merge commit.
> >
> >  COMMANDS
> >  --------
> >
> >  The following commands are available to rewrite history in different ways:
> >
> > +`drop <commit>`::
> > +	Remove the specified commit from the history. All descendants of the
> > +	commit are replayed directly onto its parent.
> > ++
> > +The root commit cannot be dropped as that may lead to edge cases where refs
> > +end up with no commits anymore. Merge commits cannot be dropped either; see
> > +LIMITATIONS.
> 
> Should section names be “bare” or quoted like "LIMITATIONS"?
> I don’t know.
> 
> Maybe add “above” since it’s a previous section.

Hm. I think I'd prefer to keep this as-is, as we already have preexisting documentation in the same manpage that does it exactly like the above.

Show 22 quoted lines
> > ++
> > +If `HEAD` points at a commit that is to be rewritten, the index and working
> >[snip]
> > +Drop a commit
> > +~~~~~~~~~~~~~
> > +
> > +----------
> > +$ git log --oneline
> > +abc1234 (HEAD -> main) third
> > +def5678 second
> > +ghi9012 first
> > +
> > +$ git history drop def5678
> 
> I know this is only the most simple example. And I might be dragging in
> something beyond the scope of this example. But I recall one
> demonstration on the first git-history(1) series which used a lot of
> revision expressions and someone saying that they couldn’t imagine a
> workflow where this would be more interactive than bringing up the
> git-rebase(1) todo editor.
> 
> (I couldn’t find back to this right now.)
Yeah, I remember this discussion.
Show 17 quoted lines
> Although it is slower in terms of machine cycles, the keyboard instinct
> for dropping a nearby commit might be to do `git rebase -i @~10`
> (sufficiently high number) and navigating quickly in the configured
> editor, deleting the line or using the keybind for `drop`. This example
> which by implication brings up the log in order to paste the abbreviated
> hash isn’t as ergonomic in comparison.
> 
> But using a revision expression like searching the subject with
> `main^{/second}`, while not quicker probably, does distinguish itself
> from git-rebase(1) by being a pretty fast ad hoc invocation that can be
> done in one command without futzing with some weird sed(1) editor in
> order to navigate to the `second` line and deleting it, or
> something. And that’s a small win in isolation, but it segues much more
> naturally into letting you script, say, dropping the last commit that
> starts with the subject `TEMP`.
> 
> Or maybe revision expressions is too much in this context?

No, I think that's actually a good idea to demonstrate how this can be used without being too unergomonic.

Eventually I still have the idea in my mind to implement a TUI around git-history(1) that allows to drive its several subcommands without having to laboriously select the right commits. Ideally, you'd simply select the commits you care about and then pick specific actions you want to do on them, with a nice visual graph that updates after the operation. But that's a bit into the future, I guess :)

Show 36 quoted lines
> > diff --git a/t/t3454-history-drop.sh b/t/t3454-history-drop.sh
> > new file mode 100755
> > index 0000000000..37d8413e7e
> > --- /dev/null
> > +++ b/t/t3454-history-drop.sh
> > @@ -0,0 +1,513 @@
> > +#!/bin/sh
> > +
> > +test_description='tests for git-history drop subcommand'
> > +
> > +. ./test-lib.sh
> > +. "$TEST_DIRECTORY/lib-log-graph.sh"
> > +
> > +expect_graph () {
> > +	cat >expect &&
> > +	lib_test_cmp_graph --format=%s "$@"
> > +}
> > +
> > +expect_log () {
> > +	git log --format="%s" "$@" >actual &&
> > +	cat >expect &&
> > +	test_cmp expect actual
> > +}
> > +
> > +test_expect_success 'errors on missing commit argument' '
> > +	test_when_finished "rm -rf repo" &&
> > +	git init repo &&
> > +	(
> > +		cd repo &&
> > +		test_commit initial &&
> > +		test_must_fail git history drop 2>err &&
> > +		test_grep "command expects a single revision" err
> 
> Why not `test_cmp` since it’s a fixed error?
> 
> Same for a few other tests like `errors on unknown revision`.

We tend to use test_grep for cases like this, even for static error messages. I haven't really figured out myself when exactly we tend to use one form over the other, to be honest.

Show 12 quoted lines
> >[snip]
> > +test_expect_success 'errors with invalid --empty= value' '
> > +	test_when_finished "rm -rf repo" &&
> > +	git init repo &&
> > +	test_commit -C repo initial &&
> > +	test_commit -C repo second &&
> > +	test_must_fail git -C repo history drop --empty=bogus HEAD 2>err &&
> > +	test_grep "unrecognized.*--empty.*bogus" err
> > +'
> 
> Style related I guess. Most tests here use a subshell but this one uses
> `git -C`? Why is that?
No good reason, will fix.
Thanks!
Patrick
Previous: Kristoffer HaugsbakkNext: Junio C Hamano
Message 31 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.