{"thread":{"id":"65903","subject":"[PATCH v8 01/11] read-cache: split out function to drop unmerged entries to stage 0","startedAt":"2026-07-01T11:35:43Z","lastAt":"2026-07-03T20:02:04Z","messageCount":18,"participants":["Patrick Steinhardt","Junio C Hamano","Christian Couder"],"isPatch":true,"patchVersion":8,"patchTotal":11},"messages":[{"id":"546869","messageId":"20260701-b4-pks-history-drop-v8-1-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 01/11] read-cache: split out function to drop unmerged entries to stage 0","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:28Z","receivedAt":"2026-07-01T11:35:43Z","isPatch":true,"body":"In `repo_read_index_unmerged()` we read the index and then drop any\nunmerged entries to stage 0. In a subsequent commit we'll want to\nperform this operation on arbitrary indexes, not only the one of the\ngiven repository.\n\nPrepare for this by splitting out the functionality into a new function\nthat can act on an arbitrary index.\n\nWhile at it, fix a signedness mismatch when iterating through the index\ncache entries.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n read-cache-ll.h |  1 +\n read-cache.c    | 12 +++++++-----\n 2 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/read-cache-ll.h b/read-cache-ll.h\nindex 2c8b4b21b1..71b87615eb 100644\n--- a/read-cache-ll.h\n+++ b/read-cache-ll.h\n@@ -309,6 +309,7 @@ int write_locked_index(struct index_state *, struct lock_file *lock, unsigned fl\n void discard_index(struct index_state *);\n void move_index_extensions(struct index_state *dst, struct index_state *src);\n int unmerged_index(const struct index_state *);\n+int index_state_unmerged_to_stage0(struct index_state *istate);\n \n /**\n  * Returns 1 if istate differs from tree, 0 otherwise.  If tree is NULL,\ndiff --git a/read-cache.c b/read-cache.c\nindex 21829102ae..799a5bc719 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -3403,13 +3403,15 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,\n  */\n int repo_read_index_unmerged(struct repository *repo)\n {\n-\tstruct index_state *istate;\n-\tint i;\n+\trepo_read_index(repo);\n+\treturn index_state_unmerged_to_stage0(repo->index);\n+}\n+\n+int index_state_unmerged_to_stage0(struct index_state *istate)\n+{\n \tint unmerged = 0;\n \n-\trepo_read_index(repo);\n-\tistate = repo->index;\n-\tfor (i = 0; i < istate->cache_nr; i++) {\n+\tfor (unsigned int i = 0; i < istate->cache_nr; i++) {\n \t\tstruct cache_entry *ce = istate->cache[i];\n \t\tstruct cache_entry *new_ce;\n \t\tint len;\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546870","messageId":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260601-b4-pks-history-drop-v1-0-643e32340d55@pks.im","subject":"[PATCH v8 00/11] builtin/history: introduce \"drop\" subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:27Z","receivedAt":"2026-07-01T11:35:43Z","isPatch":true,"body":"Hi,\n\nthis small patch series introduces the new \"drop\" subcommand for\ngit-history(1). As a reader might guess, the command does exactly that:\ngiven a commit, it will drop that commit from the commit history and\nreplay descendant branches on top of it.\n\nChanges in v8:\n  - Pass `RESOLVE_REF_READING` to make `refs_resolve_ref_unsafe()`\n    return a NULL pointer when it cannot resolve the reference.\n  - Drop unneeded code that sets `head_target = \"HEAD\"` on detached\n    HEAD.\n  - Add a test case that verifies that we can drop commits with\n    \"--update-refs=head\" and a detached HEAD.\n  - Link to v7: https://patch.msgid.link/20260629-b4-pks-history-drop-v7-0-6e9392a957d8@pks.im\n\nChanges in v7:\n  - Expose `replay_result_queue_update()` so that we don't have to\n    duplicate its functionality.\n  - Add missing SOB.\n  - Link to v6: https://patch.msgid.link/20260615-b4-pks-history-drop-v6-0-2e329e536d78@pks.im\n\nChanges in v6:\n  - Fix bad interactions of DRY_RUN with UPDATE_HEAD\n  - Link to v5: https://patch.msgid.link/20260611-b4-pks-history-drop-v5-0-34d35725559c@pks.im\n\nChanges in v5:\n  - Reject UPDATE_ORIG_HEAD without UPDATE_HEAD.\n  - Link to v4: https://patch.msgid.link/20260610-b4-pks-history-drop-v4-0-70d5f0ae8c25@pks.im\n\nChanges in v4:\n  - Remove the `SKIP_REF_UPDATES` flag in favor of a new `UPDATE_HEAD`\n    flag, as suggested by Phillip.\n  - Rename `reset_head()` to `reset_working_tree()`. This better matches\n    the new scope of the function, and it helps us to catch any\n    in-flight patches that would now have to set the `UPDATE_HEAD` flag.\n  - Link to v3: https://patch.msgid.link/20260608-b4-pks-history-drop-v3-0-84ca8e43e937@pks.im\n\nChanges in v3:\n  - Fix commit message typos.\n  - Make `update_orig_head` and `skip_ref_updates` mutually exclusive.\n  - Use fancy revisions to specify the commit to drop in the example\n    section.\n  - Detect conflicting changes in the index/working tree in dry-run\n    mode.\n  - Consistently use a subshell.\n  - Rename `RESET_HEAD_ORIG_HEAD` to `RESET_HEAD_UPDATE_ORIG_HEAD`.\n  - Link to v2: https://patch.msgid.link/20260603-b4-pks-history-drop-v2-0-742cb5b5176d@pks.im\n\nChanges in v2:\n  - Reworked `update_worktree()` to use `reset_head()`, which required a\n    bunch of changes to `reset_head()`.\n  - Consistently mention the commit that cannot be dropped as part of\n    error messages.\n  - Adapt error message to not use backticks anymore.\n  - Drop redundant \"--graph\" flag in a test helper.\n  - Link to v1: https://patch.msgid.link/20260601-b4-pks-history-drop-v1-0-643e32340d55@pks.im\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (11):\n      read-cache: split out function to drop unmerged entries to stage 0\n      reset: drop `USE_THE_REPOSITORY_VARIABLE`\n      reset: rename `reset_head()`\n      reset: modernize flags passed to `reset_working_tree()`\n      reset: introduce dry-run mode\n      reset: introduce ability to skip updating HEAD\n      reset: allow the caller to specify the current HEAD object\n      reset: stop assuming that the caller passes in a clean index\n      replay: expose `replay_result_queue_update()`\n      builtin/history: split handling of ref updates into two phases\n      builtin/history: implement \"drop\" subcommand\n\n Documentation/git-history.adoc |  38 ++-\n builtin/history.c              | 284 ++++++++++++++++++---\n builtin/rebase.c               |  41 +--\n read-cache-ll.h                |   1 +\n read-cache.c                   |  12 +-\n replay.c                       |   8 +-\n replay.h                       |   5 +\n reset.c                        | 102 +++++---\n reset.h                        |  51 ++--\n sequencer.c                    |  17 +-\n t/meson.build                  |   1 +\n t/t3454-history-drop.sh        | 561 +++++++++++++++++++++++++++++++++++++++++\n 12 files changed, 1000 insertions(+), 121 deletions(-)\n\nRange-diff versus v7:\n\n 1:  4b8702dbff =  1:  8145bb1408 read-cache: split out function to drop unmerged entries to stage 0\n 2:  1794f27cc4 =  2:  022d65d3db reset: drop `USE_THE_REPOSITORY_VARIABLE`\n 3:  2cb6c21f6a =  3:  c37abd69d3 reset: rename `reset_head()`\n 4:  55fb296c39 =  4:  84f80ff33b reset: modernize flags passed to `reset_working_tree()`\n 5:  b57d52b5ca =  5:  2465dcf8ec reset: introduce dry-run mode\n 6:  a54dbccb17 =  6:  65b1853ce4 reset: introduce ability to skip updating HEAD\n 7:  f22a1c9b70 =  7:  acfc768574 reset: allow the caller to specify the current HEAD object\n 8:  5ec7867767 =  8:  8e2d3fa7b3 reset: stop assuming that the caller passes in a clean index\n 9:  d8c9548408 =  9:  80015c6cec replay: expose `replay_result_queue_update()`\n10:  d01ce11892 = 10:  b518dcd5ef builtin/history: split handling of ref updates into two phases\n11:  1ee3600b98 ! 11:  963636e72c builtin/history: implement \"drop\" subcommand\n    @@ builtin/history.c: static int cmd_history_split(int argc,\n     +\n     +\t*changed = false;\n     +\n    -+\thead_target = refs_resolve_ref_unsafe(get_main_ref_store(repo),\n    -+\t\t\t\t\t      \"HEAD\", RESOLVE_REF_NO_RECURSE,\n    ++\thead_target = refs_resolve_ref_unsafe(get_main_ref_store(repo), \"HEAD\",\n    ++\t\t\t\t\t      RESOLVE_REF_NO_RECURSE | RESOLVE_REF_READING,\n     +\t\t\t\t\t      NULL, &head_flags);\n     +\tif (!head_target)\n     +\t\treturn error(_(\"cannot look up HEAD\"));\n    -+\tif (!(head_flags & REF_ISSYMREF))\n    -+\t\thead_target = \"HEAD\";\n     +\n     +\tfor (size_t i = 0; i < result->updates_nr; i++) {\n     +\t\tif (!strcmp(result->updates[i].refname, head_target)) {\n    @@ t/t3454-history-drop.sh (new)\n     +\t)\n     +'\n     +\n    ++test_expect_success '--update-refs=head can rewrite detached HEAD' '\n    ++\ttest_when_finished \"rm -rf repo\" &&\n    ++\tgit init repo --initial-branch=main &&\n    ++\t(\n    ++\t\tcd repo &&\n    ++\t\ttest_commit first &&\n    ++\t\ttest_commit second &&\n    ++\t\ttest_commit third &&\n    ++\t\tgit switch --detach HEAD &&\n    ++\n    ++\t\tgit history drop --update-refs=head second &&\n    ++\n    ++\t\texpect_log HEAD <<-\\EOF &&\n    ++\t\tthird\n    ++\t\tfirst\n    ++\t\tEOF\n    ++\t\texpect_log main <<-\\EOF\n    ++\t\tthird\n    ++\t\tsecond\n    ++\t\tfirst\n    ++\t\tEOF\n    ++\t)\n    ++'\n    ++\n     +test_expect_success 'conflict with replayed commit aborts cleanly' '\n     +\ttest_when_finished \"rm -rf repo\" &&\n     +\tgit init repo &&\n\n---\nbase-commit: 1666c1265231b0bc5f613fbbf3f0a9896cdef76e\nchange-id: 20260601-b4-pks-history-drop-28f6c6399e7b\n\n"},{"id":"546871","messageId":"20260701-b4-pks-history-drop-v8-2-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 02/11] reset: drop `USE_THE_REPOSITORY_VARIABLE`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:29Z","receivedAt":"2026-07-01T11:35:45Z","isPatch":true,"body":"In \"reset.c\" we still have references to `the_repository`, even though\nthe only entry point into the file already receives a repository as\nparameter.\n\nUpdate all uses of `the_repository` to instead use the passed-in repo\nand drop `USE_THE_REPOSITORY_VARIABLE`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n reset.c | 27 +++++++++++++--------------\n 1 file changed, 13 insertions(+), 14 deletions(-)\n\ndiff --git a/reset.c b/reset.c\nindex 46e30e6394..3b3cb74dab 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"cache-tree.h\"\n #include \"gettext.h\"\n@@ -13,7 +11,8 @@\n #include \"unpack-trees.h\"\n #include \"hook.h\"\n \n-static int update_refs(const struct reset_head_opts *opts,\n+static int update_refs(struct repository *repo,\n+\t\t       const struct reset_head_opts *opts,\n \t\t       const struct object_id *oid,\n \t\t       const struct object_id *head)\n {\n@@ -42,19 +41,19 @@ static int update_refs(const struct reset_head_opts *opts,\n \tprefix_len = msg.len;\n \n \tif (update_orig_head) {\n-\t\tif (!repo_get_oid(the_repository, \"ORIG_HEAD\", &oid_old_orig))\n+\t\tif (!repo_get_oid(repo, \"ORIG_HEAD\", &oid_old_orig))\n \t\t\told_orig = &oid_old_orig;\n \t\tif (head) {\n \t\t\tif (!reflog_orig_head) {\n \t\t\t\tstrbuf_addstr(&msg, \"updating ORIG_HEAD\");\n \t\t\t\treflog_orig_head = msg.buf;\n \t\t\t}\n-\t\t\trefs_update_ref(get_main_ref_store(the_repository),\n+\t\t\trefs_update_ref(get_main_ref_store(repo),\n \t\t\t\t\treflog_orig_head, \"ORIG_HEAD\",\n \t\t\t\t\torig_head ? orig_head : head,\n \t\t\t\t\told_orig, 0, UPDATE_REFS_MSG_ON_ERR);\n \t\t} else if (old_orig)\n-\t\t\trefs_delete_ref(get_main_ref_store(the_repository),\n+\t\t\trefs_delete_ref(get_main_ref_store(repo),\n \t\t\t\t\tNULL, \"ORIG_HEAD\", old_orig, 0);\n \t}\n \n@@ -64,23 +63,23 @@ static int update_refs(const struct reset_head_opts *opts,\n \t\treflog_head = msg.buf;\n \t}\n \tif (!switch_to_branch)\n-\t\tret = refs_update_ref(get_main_ref_store(the_repository),\n+\t\tret = refs_update_ref(get_main_ref_store(repo),\n \t\t\t\t      reflog_head, \"HEAD\", oid, head,\n \t\t\t\t      detach_head ? REF_NO_DEREF : 0,\n \t\t\t\t      UPDATE_REFS_MSG_ON_ERR);\n \telse {\n-\t\tret = refs_update_ref(get_main_ref_store(the_repository),\n+\t\tret = refs_update_ref(get_main_ref_store(repo),\n \t\t\t\t      reflog_branch ? reflog_branch : reflog_head,\n \t\t\t\t      switch_to_branch, oid, NULL, 0,\n \t\t\t\t      UPDATE_REFS_MSG_ON_ERR);\n \t\tif (!ret)\n-\t\t\tret = refs_update_symref(get_main_ref_store(the_repository),\n+\t\t\tret = refs_update_symref(get_main_ref_store(repo),\n \t\t\t\t\t\t \"HEAD\", switch_to_branch,\n \t\t\t\t\t\t reflog_head);\n \t}\n \tif (!ret && run_hook)\n-\t\trun_hooks_l(the_repository, \"post-checkout\",\n-\t\t\t    oid_to_hex(head ? head : null_oid(the_hash_algo)),\n+\t\trun_hooks_l(repo, \"post-checkout\",\n+\t\t\t    oid_to_hex(head ? head : null_oid(repo->hash_algo)),\n \t\t\t    oid_to_hex(oid), \"1\", NULL);\n \tstrbuf_release(&msg);\n \treturn ret;\n@@ -126,7 +125,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)\n \t\toid = &head_oid;\n \n \tif (refs_only)\n-\t\treturn update_refs(opts, oid, head);\n+\t\treturn update_refs(r, opts, oid, head);\n \n \taction = reset_hard ? \"reset\" : \"checkout\";\n \tsetup_unpack_trees_porcelain(&unpack_tree_opts, action);\n@@ -163,7 +162,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)\n \t\tgoto leave_reset_head;\n \t}\n \n-\ttree = repo_parse_tree_indirect(the_repository, oid);\n+\ttree = repo_parse_tree_indirect(r, oid);\n \tif (!tree) {\n \t\tret = error(_(\"unable to read tree (%s)\"), oid_to_hex(oid));\n \t\tgoto leave_reset_head;\n@@ -177,7 +176,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)\n \t}\n \n \tif (oid != &head_oid || update_orig_head || switch_to_branch)\n-\t\tret = update_refs(opts, oid, head);\n+\t\tret = update_refs(r, opts, oid, head);\n \n leave_reset_head:\n \trollback_lock_file(&lock);\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546872","messageId":"20260701-b4-pks-history-drop-v8-3-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 03/11] reset: rename `reset_head()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:30Z","receivedAt":"2026-07-01T11:35:47Z","isPatch":true,"body":"In a subsequent commit we're about to adapt `reset_head()` so that the\nreference update to HEAD is optional, only. At this point the function\nstarts to feel misnamed, as it doesn't necessarily have anything to do\nwith the HEAD reference anymore. The gist of the function then is that\nwe reset the working tree to a specific new commit, updating both the\nindex and the checked-out files.\n\nRename it to `reset_working_tree()` to better reflect that.\n\nNote that we don't adjust the flags yet. This will happen in a\nsubsequent commit.\n\nSuggested-by: Phillip Wood <phillip.wood123@gmail.com>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rebase.c | 20 ++++++++++----------\n reset.c          |  5 +++--\n reset.h          |  4 ++--\n sequencer.c      |  8 ++++----\n 4 files changed, 19 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex fa4f5d9306..22fbba3c62 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -592,7 +592,7 @@ static int finish_rebase(struct rebase_options *opts)\n static int move_to_original_branch(struct rebase_options *opts)\n {\n \tstruct strbuf branch_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT;\n-\tstruct reset_head_opts ropts = { 0 };\n+\tstruct reset_working_tree_options ropts = { 0 };\n \tint ret;\n \n \tif (!opts->head_name)\n@@ -610,7 +610,7 @@ static int move_to_original_branch(struct rebase_options *opts)\n \tropts.flags = RESET_HEAD_REFS_ONLY;\n \tropts.branch_msg = branch_reflog.buf;\n \tropts.head_msg = head_reflog.buf;\n-\tret = reset_head(the_repository, &ropts);\n+\tret = reset_working_tree(the_repository, &ropts);\n \n \tstrbuf_release(&branch_reflog);\n \tstrbuf_release(&head_reflog);\n@@ -685,7 +685,7 @@ static int run_am(struct rebase_options *opts)\n \n \tstatus = run_command(&format_patch);\n \tif (status) {\n-\t\tstruct reset_head_opts ropts = { 0 };\n+\t\tstruct reset_working_tree_options ropts = { 0 };\n \t\tunlink(rebased_patches);\n \t\tfree(rebased_patches);\n \t\tchild_process_clear(&am);\n@@ -693,7 +693,7 @@ static int run_am(struct rebase_options *opts)\n \t\tropts.oid = &opts->orig_head->object.oid;\n \t\tropts.branch = opts->head_name;\n \t\tropts.default_reflog_action = opts->reflog_action;\n-\t\treset_head(the_repository, &ropts);\n+\t\treset_working_tree(the_repository, &ropts);\n \t\terror(_(\"\\ngit encountered an error while preparing the \"\n \t\t\t\"patches to replay\\n\"\n \t\t\t\"these revisions:\\n\"\n@@ -855,7 +855,7 @@ static int rebase_config(const char *var, const char *value,\n static int checkout_up_to_date(struct rebase_options *options)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tstruct reset_head_opts ropts = { 0 };\n+\tstruct reset_working_tree_options ropts = { 0 };\n \tint ret = 0;\n \n \tstrbuf_addf(&buf, \"%s: checkout %s\",\n@@ -866,7 +866,7 @@ static int checkout_up_to_date(struct rebase_options *options)\n \tif (!ropts.branch)\n \t\tropts.flags |=  RESET_HEAD_DETACH;\n \tropts.head_msg = buf.buf;\n-\tif (reset_head(the_repository, &ropts) < 0)\n+\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\tret = error(_(\"could not switch to %s\"), options->switch_to);\n \tstrbuf_release(&buf);\n \n@@ -1116,7 +1116,7 @@ int cmd_rebase(int argc,\n \tint reschedule_failed_exec = -1;\n \tint allow_preemptive_ff = 1;\n \tint preserve_merges_selected = 0;\n-\tstruct reset_head_opts ropts = { 0 };\n+\tstruct reset_working_tree_options ropts = { 0 };\n \tstruct option builtin_rebase_options[] = {\n \t\tOPT_STRING(0, \"onto\", &options.onto_name,\n \t\t\t   N_(\"revision\"),\n@@ -1385,7 +1385,7 @@ int cmd_rebase(int argc,\n \t\trerere_clear(the_repository, &merge_rr);\n \t\tstring_list_clear(&merge_rr, 1);\n \t\tropts.flags = RESET_HEAD_HARD;\n-\t\tif (reset_head(the_repository, &ropts) < 0)\n+\t\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\t\tdie(_(\"could not discard worktree changes\"));\n \t\tremove_branch_state(the_repository, 0);\n \t\tif (read_basic_state(&options))\n@@ -1410,7 +1410,7 @@ int cmd_rebase(int argc,\n \t\tropts.head_msg = head_msg.buf;\n \t\tropts.branch = options.head_name;\n \t\tropts.flags = RESET_HEAD_HARD;\n-\t\tif (reset_head(the_repository, &ropts) < 0)\n+\t\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\t\tdie(_(\"could not move back to %s\"),\n \t\t\t    oid_to_hex(&options.orig_head->object.oid));\n \t\tstrbuf_release(&head_msg);\n@@ -1880,7 +1880,7 @@ int cmd_rebase(int argc,\n \t\t\tRESET_HEAD_RUN_POST_CHECKOUT_HOOK;\n \tropts.head_msg = msg.buf;\n \tropts.default_reflog_action = options.reflog_action;\n-\tif (reset_head(the_repository, &ropts)) {\n+\tif (reset_working_tree(the_repository, &ropts)) {\n \t\tret = error(_(\"Could not detach HEAD\"));\n \t\tgoto cleanup_autostash;\n \t}\ndiff --git a/reset.c b/reset.c\nindex 3b3cb74dab..799596398b 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -12,7 +12,7 @@\n #include \"hook.h\"\n \n static int update_refs(struct repository *repo,\n-\t\t       const struct reset_head_opts *opts,\n+\t\t       const struct reset_working_tree_options *opts,\n \t\t       const struct object_id *oid,\n \t\t       const struct object_id *head)\n {\n@@ -85,7 +85,8 @@ static int update_refs(struct repository *repo,\n \treturn ret;\n }\n \n-int reset_head(struct repository *r, const struct reset_head_opts *opts)\n+int reset_working_tree(struct repository *r,\n+\t\t       const struct reset_working_tree_options *opts)\n {\n \tconst struct object_id *oid = opts->oid;\n \tconst char *switch_to_branch = opts->branch;\ndiff --git a/reset.h b/reset.h\nindex a28f81829d..f130152014 100644\n--- a/reset.h\n+++ b/reset.h\n@@ -17,7 +17,7 @@\n /* Update ORIG_HEAD as well as HEAD */\n #define RESET_ORIG_HEAD (1<<4)\n \n-struct reset_head_opts {\n+struct reset_working_tree_options {\n \t/*\n \t * The commit to checkout/reset to. Defaults to HEAD.\n \t */\n@@ -55,6 +55,6 @@ struct reset_head_opts {\n \tconst char *default_reflog_action;\n };\n \n-int reset_head(struct repository *r, const struct reset_head_opts *opts);\n+int reset_working_tree(struct repository *r, const struct reset_working_tree_options *opts);\n \n #endif\ndiff --git a/sequencer.c b/sequencer.c\nindex 1ee4b2875b..d73ecf0384 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -4677,7 +4677,7 @@ static void create_autostash_internal(struct repository *r,\n \tif (has_unstaged_changes(r, 1) ||\n \t    has_uncommitted_changes(r, 1)) {\n \t\tstruct child_process stash = CHILD_PROCESS_INIT;\n-\t\tstruct reset_head_opts ropts = { .flags = RESET_HEAD_HARD };\n+\t\tstruct reset_working_tree_options ropts = { .flags = RESET_HEAD_HARD };\n \t\tstruct object_id oid;\n \n \t\tstrvec_pushl(&stash.args,\n@@ -4707,7 +4707,7 @@ static void create_autostash_internal(struct repository *r,\n \n \t\tif (!silent)\n \t\t\tprintf(_(\"Created autostash: %s\\n\"), buf.buf);\n-\t\tif (reset_head(r, &ropts) < 0)\n+\t\tif (reset_working_tree(r, &ropts) < 0)\n \t\t\tdie(_(\"could not reset --hard\"));\n \t\tdiscard_index(r->index);\n \t\tif (repo_read_index(r) < 0)\n@@ -4867,7 +4867,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,\n \t\t\t const char *onto_name, const struct object_id *onto,\n \t\t\t const struct object_id *orig_head)\n {\n-\tstruct reset_head_opts ropts = {\n+\tstruct reset_working_tree_options ropts = {\n \t\t.oid = onto,\n \t\t.orig_head = orig_head,\n \t\t.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |\n@@ -4876,7 +4876,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,\n \t\t\t\t\t   onto_name),\n \t\t.default_reflog_action = sequencer_reflog_action(opts)\n \t};\n-\tif (reset_head(r, &ropts)) {\n+\tif (reset_working_tree(r, &ropts)) {\n \t\tapply_autostash(rebase_path_autostash());\n \t\tsequencer_remove_state(opts);\n \t\treturn error(_(\"could not detach HEAD\"));\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546873","messageId":"20260701-b4-pks-history-drop-v8-4-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 04/11] reset: modernize flags passed to `reset_working_tree()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:31Z","receivedAt":"2026-07-01T11:35:49Z","isPatch":true,"body":"The flags passed to `reset_working_tree()` are declared as defines. This\nhas fallen a bit out of practice nowadays, where we instead prefer to\nuse enums. Furthermore, the prefix of those flags does not match the\nfunction name anymore after the rename in the preceding commit.\n\nAdapt the code to follow modern best practices and adapt the flag names.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rebase.c | 15 ++++++++-------\n reset.c          | 12 ++++++------\n reset.h          | 31 +++++++++++++++++++------------\n sequencer.c      |  9 ++++++---\n 4 files changed, 39 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 22fbba3c62..06dcbaf5e8 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -607,7 +607,7 @@ static int move_to_original_branch(struct rebase_options *opts)\n \tstrbuf_addf(&head_reflog, \"%s (finish): returning to %s\",\n \t\t    opts->reflog_action, opts->head_name);\n \tropts.branch = opts->head_name;\n-\tropts.flags = RESET_HEAD_REFS_ONLY;\n+\tropts.flags = RESET_WORKING_TREE_REFS_ONLY;\n \tropts.branch_msg = branch_reflog.buf;\n \tropts.head_msg = head_reflog.buf;\n \tret = reset_working_tree(the_repository, &ropts);\n@@ -862,9 +862,9 @@ static int checkout_up_to_date(struct rebase_options *options)\n \t\t    options->reflog_action, options->switch_to);\n \tropts.oid = &options->orig_head->object.oid;\n \tropts.branch = options->head_name;\n-\tropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK;\n+\tropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;\n \tif (!ropts.branch)\n-\t\tropts.flags |=  RESET_HEAD_DETACH;\n+\t\tropts.flags |=  RESET_WORKING_TREE_DETACH;\n \tropts.head_msg = buf.buf;\n \tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\tret = error(_(\"could not switch to %s\"), options->switch_to);\n@@ -1384,7 +1384,7 @@ int cmd_rebase(int argc,\n \n \t\trerere_clear(the_repository, &merge_rr);\n \t\tstring_list_clear(&merge_rr, 1);\n-\t\tropts.flags = RESET_HEAD_HARD;\n+\t\tropts.flags = RESET_WORKING_TREE_HARD;\n \t\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\t\tdie(_(\"could not discard worktree changes\"));\n \t\tremove_branch_state(the_repository, 0);\n@@ -1409,7 +1409,7 @@ int cmd_rebase(int argc,\n \t\tropts.oid = &options.orig_head->object.oid;\n \t\tropts.head_msg = head_msg.buf;\n \t\tropts.branch = options.head_name;\n-\t\tropts.flags = RESET_HEAD_HARD;\n+\t\tropts.flags = RESET_WORKING_TREE_HARD;\n \t\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\t\tdie(_(\"could not move back to %s\"),\n \t\t\t    oid_to_hex(&options.orig_head->object.oid));\n@@ -1876,8 +1876,9 @@ int cmd_rebase(int argc,\n \t\t    options.reflog_action, options.onto_name);\n \tropts.oid = &options.onto->object.oid;\n \tropts.orig_head = &options.orig_head->object.oid;\n-\tropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |\n-\t\t\tRESET_HEAD_RUN_POST_CHECKOUT_HOOK;\n+\tropts.flags = RESET_WORKING_TREE_DETACH |\n+\t\t      RESET_WORKING_TREE_UPDATE_ORIG_HEAD |\n+\t\t      RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;\n \tropts.head_msg = msg.buf;\n \tropts.default_reflog_action = options.reflog_action;\n \tif (reset_working_tree(the_repository, &ropts)) {\ndiff --git a/reset.c b/reset.c\nindex 799596398b..4ca7f23a25 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -16,9 +16,9 @@ static int update_refs(struct repository *repo,\n \t\t       const struct object_id *oid,\n \t\t       const struct object_id *head)\n {\n-\tunsigned detach_head = opts->flags & RESET_HEAD_DETACH;\n-\tunsigned run_hook = opts->flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;\n-\tunsigned update_orig_head = opts->flags & RESET_ORIG_HEAD;\n+\tunsigned detach_head = opts->flags & RESET_WORKING_TREE_DETACH;\n+\tunsigned run_hook = opts->flags & RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;\n+\tunsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD;\n \tconst struct object_id *orig_head = opts->orig_head;\n \tconst char *switch_to_branch = opts->branch;\n \tconst char *reflog_branch = opts->branch_msg;\n@@ -90,9 +90,9 @@ int reset_working_tree(struct repository *r,\n {\n \tconst struct object_id *oid = opts->oid;\n \tconst char *switch_to_branch = opts->branch;\n-\tunsigned reset_hard = opts->flags & RESET_HEAD_HARD;\n-\tunsigned refs_only = opts->flags & RESET_HEAD_REFS_ONLY;\n-\tunsigned update_orig_head = opts->flags & RESET_ORIG_HEAD;\n+\tunsigned reset_hard = opts->flags & RESET_WORKING_TREE_HARD;\n+\tunsigned refs_only = opts->flags & RESET_WORKING_TREE_REFS_ONLY;\n+\tunsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD;\n \tstruct object_id *head = NULL, head_oid;\n \tstruct tree_desc desc[2] = { { NULL }, { NULL } };\n \tstruct lock_file lock = LOCK_INIT;\ndiff --git a/reset.h b/reset.h\nindex f130152014..2e5826de99 100644\n--- a/reset.h\n+++ b/reset.h\n@@ -6,16 +6,22 @@\n \n #define GIT_REFLOG_ACTION_ENVIRONMENT \"GIT_REFLOG_ACTION\"\n \n-/* Request a detached checkout */\n-#define RESET_HEAD_DETACH (1<<0)\n-/* Request a reset rather than a checkout */\n-#define RESET_HEAD_HARD (1<<1)\n-/* Run the post-checkout hook */\n-#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)\n-/* Only update refs, do not touch the worktree */\n-#define RESET_HEAD_REFS_ONLY (1<<3)\n-/* Update ORIG_HEAD as well as HEAD */\n-#define RESET_ORIG_HEAD (1<<4)\n+enum reset_working_tree_flags {\n+\t/* Request a detached checkout */\n+\tRESET_WORKING_TREE_DETACH = (1 << 0),\n+\n+\t/* Request a reset rather than a checkout */\n+\tRESET_WORKING_TREE_HARD = (1 << 1),\n+\n+\t/* Run the post-checkout hook */\n+\tRESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK = (1 << 2),\n+\n+\t/* Only update refs, do not touch the worktree */\n+\tRESET_WORKING_TREE_REFS_ONLY = (1 << 3),\n+\n+\t/* Update ORIG_HEAD as well as HEAD */\n+\tRESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 4),\n+};\n \n struct reset_working_tree_options {\n \t/*\n@@ -33,7 +39,7 @@ struct reset_working_tree_options {\n \t/*\n \t * Flags defined above.\n \t */\n-\tunsigned flags;\n+\tenum reset_working_tree_flags flags;\n \t/*\n \t * Optional reflog message for branch, defaults to head_msg.\n \t */\n@@ -45,7 +51,8 @@ struct reset_working_tree_options {\n \tconst char *head_msg;\n \t/*\n \t * Optional reflog message for ORIG_HEAD, if this omitted and flags\n-\t * contains RESET_ORIG_HEAD then default_reflog_action must be given.\n+\t * contains RESET_WORKING_TREE_UPDATE_ORIG_HEAD then\n+\t * default_reflog_action must be given.\n \t */\n \tconst char *orig_head_msg;\n \t/*\ndiff --git a/sequencer.c b/sequencer.c\nindex d73ecf0384..4efe831178 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -4677,7 +4677,9 @@ static void create_autostash_internal(struct repository *r,\n \tif (has_unstaged_changes(r, 1) ||\n \t    has_uncommitted_changes(r, 1)) {\n \t\tstruct child_process stash = CHILD_PROCESS_INIT;\n-\t\tstruct reset_working_tree_options ropts = { .flags = RESET_HEAD_HARD };\n+\t\tstruct reset_working_tree_options ropts = {\n+\t\t\t.flags = RESET_WORKING_TREE_HARD,\n+\t\t};\n \t\tstruct object_id oid;\n \n \t\tstrvec_pushl(&stash.args,\n@@ -4870,8 +4872,9 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,\n \tstruct reset_working_tree_options ropts = {\n \t\t.oid = onto,\n \t\t.orig_head = orig_head,\n-\t\t.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |\n-\t\t\t\tRESET_HEAD_RUN_POST_CHECKOUT_HOOK,\n+\t\t.flags = RESET_WORKING_TREE_DETACH |\n+\t\t\t RESET_WORKING_TREE_UPDATE_ORIG_HEAD |\n+\t\t\t RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK,\n \t\t.head_msg = reflog_message(opts, \"start\", \"checkout %s\",\n \t\t\t\t\t   onto_name),\n \t\t.default_reflog_action = sequencer_reflog_action(opts)\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546874","messageId":"20260701-b4-pks-history-drop-v8-5-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 05/11] reset: introduce dry-run mode","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:32Z","receivedAt":"2026-07-01T11:35:53Z","isPatch":true,"body":"In a subsequent commit we'll add another caller to `reset_working_tree()`\nthat wants to perform a dry-run check of whether it would be possible to\nupdate the index and working tree when moving to a new commit. Introduce\na new flag that lets the caller perform this operation.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n reset.c | 44 +++++++++++++++++++++++++++++++++-----------\n reset.h |  6 ++++++\n 2 files changed, 39 insertions(+), 11 deletions(-)\n\ndiff --git a/reset.c b/reset.c\nindex 4ca7f23a25..99f2c1b012 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -93,11 +93,14 @@ int reset_working_tree(struct repository *r,\n \tunsigned reset_hard = opts->flags & RESET_WORKING_TREE_HARD;\n \tunsigned refs_only = opts->flags & RESET_WORKING_TREE_REFS_ONLY;\n \tunsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD;\n+\tunsigned dry_run = opts->flags & RESET_WORKING_TREE_DRY_RUN;\n \tstruct object_id *head = NULL, head_oid;\n \tstruct tree_desc desc[2] = { { NULL }, { NULL } };\n \tstruct lock_file lock = LOCK_INIT;\n \tstruct unpack_trees_options unpack_tree_opts = { 0 };\n \tstruct tree *tree;\n+\tstruct index_state scratch_index = INDEX_STATE_INIT(r);\n+\tstruct index_state *istate;\n \tconst char *action;\n \tint ret = 0, nr = 0;\n \n@@ -110,7 +113,7 @@ int reset_working_tree(struct repository *r,\n \tif (opts->branch_msg && !opts->branch)\n \t\tBUG(\"branch reflog message given without a branch\");\n \n-\tif (!refs_only && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {\n+\tif (!refs_only && !dry_run && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {\n \t\tret = -1;\n \t\tgoto leave_reset_head;\n \t}\n@@ -125,16 +128,36 @@ int reset_working_tree(struct repository *r,\n \tif (!oid)\n \t\toid = &head_oid;\n \n-\tif (refs_only)\n-\t\treturn update_refs(r, opts, oid, head);\n+\tif (refs_only) {\n+\t\tif (!dry_run)\n+\t\t\treturn update_refs(r, opts, oid, head);\n+\t\treturn 0;\n+\t}\n+\n+\tif (dry_run) {\n+\t\tif (read_index_from(&scratch_index, r->index_file, r->gitdir) < 0 ||\n+\t\t    index_state_unmerged_to_stage0(&scratch_index) < 0) {\n+\t\t\tret = error(_(\"could not read index\"));\n+\t\t\tgoto leave_reset_head;\n+\t\t}\n+\n+\t\tistate = &scratch_index;\n+\t} else {\n+\t\tif (repo_read_index_unmerged(r) < 0) {\n+\t\t\tret = error(_(\"could not read index\"));\n+\t\t\tgoto leave_reset_head;\n+\t\t}\n+\t\tistate = r->index;\n+\t}\n \n \taction = reset_hard ? \"reset\" : \"checkout\";\n \tsetup_unpack_trees_porcelain(&unpack_tree_opts, action);\n \tunpack_tree_opts.head_idx = 1;\n-\tunpack_tree_opts.src_index = r->index;\n-\tunpack_tree_opts.dst_index = r->index;\n+\tunpack_tree_opts.src_index = istate;\n+\tunpack_tree_opts.dst_index = istate;\n \tunpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge;\n-\tunpack_tree_opts.update = 1;\n+\tunpack_tree_opts.update = !dry_run;\n+\tunpack_tree_opts.dry_run = dry_run;\n \tunpack_tree_opts.merge = 1;\n \tunpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */\n \tunpack_tree_opts.skip_cache_tree_update = 1;\n@@ -142,11 +165,6 @@ int reset_working_tree(struct repository *r,\n \tif (reset_hard)\n \t\tunpack_tree_opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;\n \n-\tif (repo_read_index_unmerged(r) < 0) {\n-\t\tret = error(_(\"could not read index\"));\n-\t\tgoto leave_reset_head;\n-\t}\n-\n \tif (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) {\n \t\tret = error(_(\"failed to find tree of %s\"),\n \t\t\t    oid_to_hex(&head_oid));\n@@ -163,6 +181,9 @@ int reset_working_tree(struct repository *r,\n \t\tgoto leave_reset_head;\n \t}\n \n+\tif (dry_run)\n+\t\tgoto leave_reset_head;\n+\n \ttree = repo_parse_tree_indirect(r, oid);\n \tif (!tree) {\n \t\tret = error(_(\"unable to read tree (%s)\"), oid_to_hex(oid));\n@@ -182,6 +203,7 @@ int reset_working_tree(struct repository *r,\n leave_reset_head:\n \trollback_lock_file(&lock);\n \tclear_unpack_trees_porcelain(&unpack_tree_opts);\n+\trelease_index(&scratch_index);\n \twhile (nr)\n \t\tfree((void *)desc[--nr].buffer);\n \treturn ret;\ndiff --git a/reset.h b/reset.h\nindex 2e5826de99..898e4a1e95 100644\n--- a/reset.h\n+++ b/reset.h\n@@ -21,6 +21,12 @@ enum reset_working_tree_flags {\n \n \t/* Update ORIG_HEAD as well as HEAD */\n \tRESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 4),\n+\n+\t/*\n+\t * Perform a dry-run by performing the operation without updating\n+\t * any user-visible state.\n+\t */\n+\tRESET_WORKING_TREE_DRY_RUN = (1 << 5),\n };\n \n struct reset_working_tree_options {\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546875","messageId":"20260701-b4-pks-history-drop-v8-6-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 06/11] reset: introduce ability to skip updating HEAD","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:33Z","receivedAt":"2026-07-01T11:35:55Z","isPatch":true,"body":"In a subsequent commit we'll introduce a new caller to\n`reset_working_tree()` that really only wants to update the index and\nworking tree, without updating any references. Introduce a new flag that\nmakes the caller opt in to updating HEAD and adapt all callers to set\nthat flag.\n\nNote that in a previous iteration we instead introduced a flag that made\ncallers opt out of updating any references. This was somewhat awkward\nthough because we already have the `UPDATE_ORIG_HEAD` flag, so the\nresult was somewhat inconsistent.\n\nSuggested-by: Phillip Wood <phillip.wood123@gmail.com>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/rebase.c | 14 ++++++++++----\n reset.c          |  9 +++++++--\n reset.h          |  9 ++++++---\n sequencer.c      |  4 +++-\n 4 files changed, 26 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 06dcbaf5e8..10a306310c 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -607,7 +607,8 @@ static int move_to_original_branch(struct rebase_options *opts)\n \tstrbuf_addf(&head_reflog, \"%s (finish): returning to %s\",\n \t\t    opts->reflog_action, opts->head_name);\n \tropts.branch = opts->head_name;\n-\tropts.flags = RESET_WORKING_TREE_REFS_ONLY;\n+\tropts.flags = RESET_WORKING_TREE_REFS_ONLY |\n+\t\t      RESET_WORKING_TREE_UPDATE_HEAD;\n \tropts.branch_msg = branch_reflog.buf;\n \tropts.head_msg = head_reflog.buf;\n \tret = reset_working_tree(the_repository, &ropts);\n@@ -693,6 +694,7 @@ static int run_am(struct rebase_options *opts)\n \t\tropts.oid = &opts->orig_head->object.oid;\n \t\tropts.branch = opts->head_name;\n \t\tropts.default_reflog_action = opts->reflog_action;\n+\t\tropts.flags = RESET_WORKING_TREE_UPDATE_HEAD;\n \t\treset_working_tree(the_repository, &ropts);\n \t\terror(_(\"\\ngit encountered an error while preparing the \"\n \t\t\t\"patches to replay\\n\"\n@@ -862,7 +864,8 @@ static int checkout_up_to_date(struct rebase_options *options)\n \t\t    options->reflog_action, options->switch_to);\n \tropts.oid = &options->orig_head->object.oid;\n \tropts.branch = options->head_name;\n-\tropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;\n+\tropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK |\n+\t\t      RESET_WORKING_TREE_UPDATE_HEAD;\n \tif (!ropts.branch)\n \t\tropts.flags |=  RESET_WORKING_TREE_DETACH;\n \tropts.head_msg = buf.buf;\n@@ -1384,7 +1387,8 @@ int cmd_rebase(int argc,\n \n \t\trerere_clear(the_repository, &merge_rr);\n \t\tstring_list_clear(&merge_rr, 1);\n-\t\tropts.flags = RESET_WORKING_TREE_HARD;\n+\t\tropts.flags = RESET_WORKING_TREE_HARD |\n+\t\t\t      RESET_WORKING_TREE_UPDATE_HEAD;\n \t\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\t\tdie(_(\"could not discard worktree changes\"));\n \t\tremove_branch_state(the_repository, 0);\n@@ -1409,7 +1413,8 @@ int cmd_rebase(int argc,\n \t\tropts.oid = &options.orig_head->object.oid;\n \t\tropts.head_msg = head_msg.buf;\n \t\tropts.branch = options.head_name;\n-\t\tropts.flags = RESET_WORKING_TREE_HARD;\n+\t\tropts.flags = RESET_WORKING_TREE_HARD |\n+\t\t\t      RESET_WORKING_TREE_UPDATE_HEAD;\n \t\tif (reset_working_tree(the_repository, &ropts) < 0)\n \t\t\tdie(_(\"could not move back to %s\"),\n \t\t\t    oid_to_hex(&options.orig_head->object.oid));\n@@ -1877,6 +1882,7 @@ int cmd_rebase(int argc,\n \tropts.oid = &options.onto->object.oid;\n \tropts.orig_head = &options.orig_head->object.oid;\n \tropts.flags = RESET_WORKING_TREE_DETACH |\n+\t\t      RESET_WORKING_TREE_UPDATE_HEAD |\n \t\t      RESET_WORKING_TREE_UPDATE_ORIG_HEAD |\n \t\t      RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;\n \tropts.head_msg = msg.buf;\ndiff --git a/reset.c b/reset.c\nindex 99f2c1b012..4bde5d8dc6 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -92,6 +92,7 @@ int reset_working_tree(struct repository *r,\n \tconst char *switch_to_branch = opts->branch;\n \tunsigned reset_hard = opts->flags & RESET_WORKING_TREE_HARD;\n \tunsigned refs_only = opts->flags & RESET_WORKING_TREE_REFS_ONLY;\n+\tunsigned update_head = opts->flags & RESET_WORKING_TREE_UPDATE_HEAD;\n \tunsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD;\n \tunsigned dry_run = opts->flags & RESET_WORKING_TREE_DRY_RUN;\n \tstruct object_id *head = NULL, head_oid;\n@@ -113,6 +114,9 @@ int reset_working_tree(struct repository *r,\n \tif (opts->branch_msg && !opts->branch)\n \t\tBUG(\"branch reflog message given without a branch\");\n \n+\tif (update_orig_head && !update_head)\n+\t\tBUG(\"cannot update ORIG_HEAD without updating HEAD\" );\n+\n \tif (!refs_only && !dry_run && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {\n \t\tret = -1;\n \t\tgoto leave_reset_head;\n@@ -129,7 +133,7 @@ int reset_working_tree(struct repository *r,\n \t\toid = &head_oid;\n \n \tif (refs_only) {\n-\t\tif (!dry_run)\n+\t\tif (!dry_run && update_head)\n \t\t\treturn update_refs(r, opts, oid, head);\n \t\treturn 0;\n \t}\n@@ -197,7 +201,8 @@ int reset_working_tree(struct repository *r,\n \t\tgoto leave_reset_head;\n \t}\n \n-\tif (oid != &head_oid || update_orig_head || switch_to_branch)\n+\tif (update_head &&\n+\t    (oid != &head_oid || update_orig_head || switch_to_branch))\n \t\tret = update_refs(r, opts, oid, head);\n \n leave_reset_head:\ndiff --git a/reset.h b/reset.h\nindex 898e4a1e95..38b2891b53 100644\n--- a/reset.h\n+++ b/reset.h\n@@ -19,14 +19,17 @@ enum reset_working_tree_flags {\n \t/* Only update refs, do not touch the worktree */\n \tRESET_WORKING_TREE_REFS_ONLY = (1 << 3),\n \n-\t/* Update ORIG_HEAD as well as HEAD */\n-\tRESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 4),\n+\t/* Update HEAD */\n+\tRESET_WORKING_TREE_UPDATE_HEAD = (1 << 4),\n+\n+\t/* Update ORIG_HEAD */\n+\tRESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 5),\n \n \t/*\n \t * Perform a dry-run by performing the operation without updating\n \t * any user-visible state.\n \t */\n-\tRESET_WORKING_TREE_DRY_RUN = (1 << 5),\n+\tRESET_WORKING_TREE_DRY_RUN = (1 << 6),\n };\n \n struct reset_working_tree_options {\ndiff --git a/sequencer.c b/sequencer.c\nindex 4efe831178..e905b1b2d9 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -4678,7 +4678,8 @@ static void create_autostash_internal(struct repository *r,\n \t    has_uncommitted_changes(r, 1)) {\n \t\tstruct child_process stash = CHILD_PROCESS_INIT;\n \t\tstruct reset_working_tree_options ropts = {\n-\t\t\t.flags = RESET_WORKING_TREE_HARD,\n+\t\t\t.flags = RESET_WORKING_TREE_HARD |\n+\t\t\t\t RESET_WORKING_TREE_UPDATE_HEAD,\n \t\t};\n \t\tstruct object_id oid;\n \n@@ -4873,6 +4874,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,\n \t\t.oid = onto,\n \t\t.orig_head = orig_head,\n \t\t.flags = RESET_WORKING_TREE_DETACH |\n+\t\t\t RESET_WORKING_TREE_UPDATE_HEAD |\n \t\t\t RESET_WORKING_TREE_UPDATE_ORIG_HEAD |\n \t\t\t RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK,\n \t\t.head_msg = reflog_message(opts, \"start\", \"checkout %s\",\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546876","messageId":"20260701-b4-pks-history-drop-v8-7-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 07/11] reset: allow the caller to specify the current HEAD object","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:34Z","receivedAt":"2026-07-01T11:35:57Z","isPatch":true,"body":"When calling `reset_working_tree()` we automatically derive the commit\nthat the callers wants to move from by reading the HEAD commit. Some\ncallers may already have resolved it, or they may want to move from a\ndifferent commit that doesn't match HEAD.\n\nIntroduce a new `oid_from` option that lets the caller specify the\ncommit.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n reset.c | 5 ++++-\n reset.h | 5 +++++\n 2 files changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/reset.c b/reset.c\nindex 4bde5d8dc6..06f375f296 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -122,7 +122,10 @@ int reset_working_tree(struct repository *r,\n \t\tgoto leave_reset_head;\n \t}\n \n-\tif (!repo_get_oid(r, \"HEAD\", &head_oid)) {\n+\tif (opts->oid_from) {\n+\t\toidcpy(&head_oid, opts->oid_from);\n+\t\thead = &head_oid;\n+\t} else if (!repo_get_oid(r, \"HEAD\", &head_oid)) {\n \t\thead = &head_oid;\n \t} else if (!oid || !reset_hard) {\n \t\tret = error(_(\"could not determine HEAD revision\"));\ndiff --git a/reset.h b/reset.h\nindex 38b2891b53..4c992ba671 100644\n--- a/reset.h\n+++ b/reset.h\n@@ -37,6 +37,11 @@ struct reset_working_tree_options {\n \t * The commit to checkout/reset to. Defaults to HEAD.\n \t */\n \tconst struct object_id *oid;\n+\t/*\n+\t * The commit to checkout/reset from when doing a two-way merge. This\n+\t * is used as one of the sides to merge.\n+\t */\n+\tconst struct object_id *oid_from;\n \t/*\n \t * Optional value to set ORIG_HEAD. Defaults to HEAD.\n \t */\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546877","messageId":"20260701-b4-pks-history-drop-v8-8-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 08/11] reset: stop assuming that the caller passes in a clean index","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:35Z","receivedAt":"2026-07-01T11:36:00Z","isPatch":true,"body":"In 652bd0211d (rebase: use 'skip_cache_tree_update' option, 2022-11-10),\nwe updated `reset_working_tree()` to stop updating the index tree cache.\nThis was done as a performance optimization: the function is only called\nby \"sequencer.c\" and \"rebase.c\", both of which assume a clean index\nbefore they perform their operation, so we know that the end result will\nbe a clean index, too. Consequently, we can skip recomputing the cache\nas we can instead use `prime_cache_tree()` directly.\n\nIn a subsequent commit we're about to add a new caller though where the\nassumption doesn't hold anymore: the index may be dirty before calling\n`reset_working_tree()`, and consequently we cannot prime the cache with\na given tree anymore as the index and tree will mismatch.\n\nAdapt the logic so that we only skip the cache tree update in case we're\ndoing a hard reset. While we could introduce logic that only skips the\nupdate in case the incoming index was dirty already, that doesn't really\nfeel worth it: after all, the mentioned commit says itself that the\nperformance improvement was negligible anyway.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n reset.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/reset.c b/reset.c\nindex 06f375f296..ff87e3e357 100644\n--- a/reset.c\n+++ b/reset.c\n@@ -167,10 +167,11 @@ int reset_working_tree(struct repository *r,\n \tunpack_tree_opts.dry_run = dry_run;\n \tunpack_tree_opts.merge = 1;\n \tunpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */\n-\tunpack_tree_opts.skip_cache_tree_update = 1;\n \tinit_checkout_metadata(&unpack_tree_opts.meta, switch_to_branch, oid, NULL);\n-\tif (reset_hard)\n+\tif (reset_hard) {\n+\t\tunpack_tree_opts.skip_cache_tree_update = 1;\n \t\tunpack_tree_opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;\n+\t}\n \n \tif (!reset_hard && !fill_tree_descriptor(r, &desc[nr++], &head_oid)) {\n \t\tret = error(_(\"failed to find tree of %s\"),\n@@ -197,7 +198,8 @@ int reset_working_tree(struct repository *r,\n \t\tgoto leave_reset_head;\n \t}\n \n-\tprime_cache_tree(r, r->index, tree);\n+\tif (reset_hard)\n+\t\tprime_cache_tree(r, r->index, tree);\n \n \tif (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) {\n \t\tret = error(_(\"could not write index\"));\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546878","messageId":"20260701-b4-pks-history-drop-v8-9-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 09/11] replay: expose `replay_result_queue_update()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:36Z","receivedAt":"2026-07-01T11:36:04Z","isPatch":true,"body":"Expose `replay_result_queue_update()`, which is used to append another\nreference update to the replay result. This function will be used in a\nsubsequent commit.\n\nSuggested-by: Christian Couder <christian.couder@gmail.com>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n replay.c | 8 ++++----\n replay.h | 5 +++++\n 2 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/replay.c b/replay.c\nindex 4ef8abb607..7c8433107b 100644\n--- a/replay.c\n+++ b/replay.c\n@@ -351,10 +351,10 @@ void replay_result_release(struct replay_result *result)\n \tfree(result->updates);\n }\n \n-static void replay_result_queue_update(struct replay_result *result,\n-\t\t\t\t       const char *refname,\n-\t\t\t\t       const struct object_id *old_oid,\n-\t\t\t\t       const struct object_id *new_oid)\n+void replay_result_queue_update(struct replay_result *result,\n+\t\t\t\tconst char *refname,\n+\t\t\t\tconst struct object_id *old_oid,\n+\t\t\t\tconst struct object_id *new_oid)\n {\n \tALLOC_GROW(result->updates, result->updates_nr + 1, result->updates_alloc);\n \tresult->updates[result->updates_nr].refname = xstrdup(refname);\ndiff --git a/replay.h b/replay.h\nindex 1851a07705..da83b65345 100644\n--- a/replay.h\n+++ b/replay.h\n@@ -80,6 +80,11 @@ struct replay_result {\n \n void replay_result_release(struct replay_result *result);\n \n+void replay_result_queue_update(struct replay_result *result,\n+\t\t\t\tconst char *refname,\n+\t\t\t\tconst struct object_id *old_oid,\n+\t\t\t\tconst struct object_id *new_oid);\n+\n /*\n  * Replay a set of commits onto a new location. Leaves both the working tree,\n  * index and references untouched. Reference updates caused by the replay will\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546879","messageId":"20260701-b4-pks-history-drop-v8-10-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 10/11] builtin/history: split handling of ref updates into two phases","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:37Z","receivedAt":"2026-07-01T11:36:05Z","isPatch":true,"body":"The function `handle_reference_updates()` is used by git-history(1) to\nupdate all references that refer to commits that have been rewritten. As\nsuch, it performs two steps:\n\n  - It gathers the references that need to be updated in the first\n    place.\n\n  - It prepares and commits the reference transaction.\n\nIn a subsequent commit we'll want to handle those two steps separately.\nPrepare for this by splitting up the function into two.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/history.c | 100 +++++++++++++++++++++++++++++++++---------------------\n 1 file changed, 62 insertions(+), 38 deletions(-)\n\ndiff --git a/builtin/history.c b/builtin/history.c\nindex 0fc06fb204..22b9fcb4a4 100644\n--- a/builtin/history.c\n+++ b/builtin/history.c\n@@ -333,21 +333,17 @@ static int handle_ref_update(struct ref_transaction *transaction,\n \t\t\t\t      NULL, NULL, 0, reflog_msg, err);\n }\n \n-static int handle_reference_updates(struct rev_info *revs,\n-\t\t\t\t    enum ref_action action,\n-\t\t\t\t    struct commit *original,\n-\t\t\t\t    struct commit *rewritten,\n-\t\t\t\t    const char *reflog_msg,\n-\t\t\t\t    int dry_run,\n-\t\t\t\t    enum replay_empty_commit_action empty)\n+static int compute_pending_ref_updates(struct rev_info *revs,\n+\t\t\t\t       enum ref_action action,\n+\t\t\t\t       struct commit *original,\n+\t\t\t\t       struct commit *rewritten,\n+\t\t\t\t       enum replay_empty_commit_action empty,\n+\t\t\t\t       struct replay_result *result)\n {\n \tconst struct name_decoration *decoration;\n \tstruct replay_revisions_options opts = {\n \t\t.empty = empty,\n \t};\n-\tstruct replay_result result = { 0 };\n-\tstruct ref_transaction *transaction = NULL;\n-\tstruct strbuf err = STRBUF_INIT;\n \tchar hex[GIT_MAX_HEXSZ + 1];\n \tbool detached_head;\n \tint head_flags = 0;\n@@ -359,34 +355,13 @@ static int handle_reference_updates(struct rev_info *revs,\n \n \topts.onto = oid_to_hex_r(hex, &rewritten->object.oid);\n \n-\tret = replay_revisions(revs, &opts, &result);\n+\tret = replay_revisions(revs, &opts, result);\n \tif (ret)\n-\t\tgoto out;\n+\t\treturn ret;\n \n \tif (action != REF_ACTION_BRANCHES && action != REF_ACTION_HEAD)\n \t\tBUG(\"unsupported ref action %d\", action);\n \n-\tif (!dry_run) {\n-\t\ttransaction = ref_store_transaction_begin(get_main_ref_store(revs->repo), 0, &err);\n-\t\tif (!transaction) {\n-\t\t\tret = error(_(\"failed to begin ref transaction: %s\"), err.buf);\n-\t\t\tgoto out;\n-\t\t}\n-\t}\n-\n-\tfor (size_t i = 0; i < result.updates_nr; i++) {\n-\t\tret = handle_ref_update(transaction,\n-\t\t\t\t\tresult.updates[i].refname,\n-\t\t\t\t\t&result.updates[i].new_oid,\n-\t\t\t\t\t&result.updates[i].old_oid,\n-\t\t\t\t\treflog_msg, &err);\n-\t\tif (ret) {\n-\t\t\tret = error(_(\"failed to update ref '%s': %s\"),\n-\t\t\t\t    result.updates[i].refname, err.buf);\n-\t\t\tgoto out;\n-\t\t}\n-\t}\n-\n \t/*\n \t * `replay_revisions()` only updates references that are\n \t * ancestors of `rewritten`, so we need to manually\n@@ -414,14 +389,41 @@ static int handle_reference_updates(struct rev_info *revs,\n \t\t    !detached_head)\n \t\t\tcontinue;\n \n+\t\treplay_result_queue_update(result, decoration->name,\n+\t\t\t\t\t   &original->object.oid,\n+\t\t\t\t\t   &rewritten->object.oid);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int apply_pending_ref_updates(struct repository *repo,\n+\t\t\t\t     const struct replay_result *result,\n+\t\t\t\t     const char *reflog_msg,\n+\t\t\t\t     int dry_run)\n+{\n+\tstruct ref_transaction *transaction = NULL;\n+\tstruct strbuf err = STRBUF_INIT;\n+\tint ret;\n+\n+\tif (!dry_run) {\n+\t\ttransaction = ref_store_transaction_begin(get_main_ref_store(repo),\n+\t\t\t\t\t\t\t  0, &err);\n+\t\tif (!transaction) {\n+\t\t\tret = error(_(\"failed to begin ref transaction: %s\"), err.buf);\n+\t\t\tgoto out;\n+\t\t}\n+\t}\n+\n+\tfor (size_t i = 0; i < result->updates_nr; i++) {\n \t\tret = handle_ref_update(transaction,\n-\t\t\t\t\tdecoration->name,\n-\t\t\t\t\t&rewritten->object.oid,\n-\t\t\t\t\t&original->object.oid,\n+\t\t\t\t\tresult->updates[i].refname,\n+\t\t\t\t\t&result->updates[i].new_oid,\n+\t\t\t\t\t&result->updates[i].old_oid,\n \t\t\t\t\treflog_msg, &err);\n \t\tif (ret) {\n \t\t\tret = error(_(\"failed to update ref '%s': %s\"),\n-\t\t\t\t    decoration->name, err.buf);\n+\t\t\t\t    result->updates[i].refname, err.buf);\n \t\t\tgoto out;\n \t\t}\n \t}\n@@ -435,11 +437,33 @@ static int handle_reference_updates(struct rev_info *revs,\n \n out:\n \tref_transaction_free(transaction);\n-\treplay_result_release(&result);\n \tstrbuf_release(&err);\n \treturn ret;\n }\n \n+static int handle_reference_updates(struct rev_info *revs,\n+\t\t\t\t    enum ref_action action,\n+\t\t\t\t    struct commit *original,\n+\t\t\t\t    struct commit *rewritten,\n+\t\t\t\t    const char *reflog_msg,\n+\t\t\t\t    int dry_run,\n+\t\t\t\t    enum replay_empty_commit_action empty)\n+{\n+\tstruct replay_result result = { 0 };\n+\tint ret;\n+\n+\tret = compute_pending_ref_updates(revs, action, original, rewritten,\n+\t\t\t\t\t  empty, &result);\n+\tif (ret)\n+\t\tgoto out;\n+\n+\tret = apply_pending_ref_updates(revs->repo, &result, reflog_msg, dry_run);\n+\n+out:\n+\treplay_result_release(&result);\n+\treturn ret;\n+}\n+\n static int commit_became_empty(struct repository *repo,\n \t\t\t       struct commit *original,\n \t\t\t       struct tree *result)\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546880","messageId":"20260701-b4-pks-history-drop-v8-11-19b5cdf1facd@pks.im","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"[PATCH v8 11/11] builtin/history: implement \"drop\" subcommand","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-01T11:35:38Z","receivedAt":"2026-07-01T11:36:08Z","isPatch":true,"body":"A common operation when editing the commit history is to drop a specific\ncommit from the history entirely, but this operation is not currently\ncovered by git-history(1).\n\nA couple of noteworthy bits:\n\n  - This is the first git-history(1) command that will ultimately result\n    in changes to both the index and the working tree. We thus have to\n    add logic to merge resulting changes into those.\n\n  - It is still not possible to replay merge commits, so this limitation\n    is inherited for the new \"drop\" command.\n\n  - For now we refuse to drop root commits. While we _can_ indeed drop\n    root commits in the general case, there are edge cases where the\n    resulting history would become completely empty. This is thus left\n    to a subsequent patch series.\n\nOther than that, most of the logic is rather straight-forward as we can\ncontinue to build on the preexisting logic in git-history(1) for most of\nthe part.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n Documentation/git-history.adoc |  38 ++-\n builtin/history.c              | 184 ++++++++++++++\n t/meson.build                  |   1 +\n t/t3454-history-drop.sh        | 561 +++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 783 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-history.adoc b/Documentation/git-history.adoc\nindex 2ba8121795..28b477cd37 100644\n--- a/Documentation/git-history.adoc\n+++ b/Documentation/git-history.adoc\n@@ -8,6 +8,7 @@ git-history - EXPERIMENTAL: Rewrite history\n SYNOPSIS\n --------\n [synopsis]\n+git history drop <commit> [--dry-run] [--update-refs=(branches|head)] [--empty=(drop|keep|abort)]\n git history fixup <commit> [--dry-run] [--update-refs=(branches|head)] [--reedit-message] [--empty=(drop|keep|abort)]\n git history reword <commit> [--dry-run] [--update-refs=(branches|head)]\n git history split <commit> [--dry-run] [--update-refs=(branches|head)] [--] [<pathspec>...]\n@@ -51,13 +52,28 @@ be stateful operations. The limitation can be lifted once (if) Git learns about\n first-class conflicts.\n \n When using `fixup` with `--empty=drop`, dropping the root commit is not yet\n-supported.\n+supported. Likewise, `drop` cannot remove the root commit or a merge commit.\n \n COMMANDS\n --------\n \n The following commands are available to rewrite history in different ways:\n \n+`drop <commit>`::\n+\tRemove the specified commit from the history. All descendants of the\n+\tcommit are replayed directly onto its parent.\n++\n+The root commit cannot be dropped as that may lead to edge cases where refs\n+end up with no commits anymore. Merge commits cannot be dropped either; see\n+LIMITATIONS.\n++\n+If `HEAD` points at a commit that is to be rewritten, the index and working\n+tree are updated to match the new `HEAD`. The command aborts before any\n+references are updated in case local modifications would be overwritten.\n++\n+If replaying any descendant would result in a conflict, the command aborts\n+with an error.\n+\n `fixup <commit>`::\n \tApply the currently staged changes to the specified commit. This is\n \tsimilar in nature to `git commit --fixup=<commit>` followed by `git\n@@ -170,6 +186,26 @@ The staged addition of `unrelated.txt` has been incorporated into the `first`\n commit. All descendant commits have been replayed on top of the rewritten\n history.\n \n+Drop a commit\n+~~~~~~~~~~~~~\n+\n+----------\n+$ git log --oneline\n+abc1234 (HEAD -> main) third\n+def5678 second\n+ghi9012 first\n+\n+$ git history drop 'main^{/second}'\n+\n+$ git log --oneline\n+jkl3456 (HEAD -> main) third\n+ghi9012 first\n+----------\n+\n+The `second` commit has been removed from the history, and `third` has been\n+replayed directly on top of `first`. All branches that pointed at the dropped\n+commit have been moved to its parent.\n+\n Split a commit\n ~~~~~~~~~~~~~~\n \ndiff --git a/builtin/history.c b/builtin/history.c\nindex 22b9fcb4a4..dd11ce2fa8 100644\n--- a/builtin/history.c\n+++ b/builtin/history.c\n@@ -17,13 +17,17 @@\n #include \"read-cache.h\"\n #include \"refs.h\"\n #include \"replay.h\"\n+#include \"reset.h\"\n #include \"revision.h\"\n #include \"sequencer.h\"\n #include \"strvec.h\"\n #include \"tree.h\"\n+#include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n #include \"wt-status.h\"\n \n+#define GIT_HISTORY_DROP_USAGE \\\n+\tN_(\"git history drop <commit> [--dry-run] [--update-refs=(branches|head)] [--empty=(drop|keep|abort)]\")\n #define GIT_HISTORY_FIXUP_USAGE \\\n \tN_(\"git history fixup <commit> [--dry-run] [--update-refs=(branches|head)] [--reedit-message] [--empty=(drop|keep|abort)]\")\n #define GIT_HISTORY_REWORD_USAGE \\\n@@ -999,12 +1003,191 @@ static int cmd_history_split(int argc,\n \treturn ret;\n }\n \n+static int update_worktree(struct repository *repo,\n+\t\t\t   const struct commit *old_head,\n+\t\t\t   const struct commit *new_head,\n+\t\t\t   bool dry_run)\n+{\n+\tstruct reset_working_tree_options opts = {\n+\t\t.oid_from = &old_head->object.oid,\n+\t\t.oid = &new_head->object.oid,\n+\t};\n+\tif (dry_run)\n+\t\topts.flags |= RESET_WORKING_TREE_DRY_RUN;\n+\treturn reset_working_tree(repo, &opts);\n+}\n+\n+static int find_head_tree_change(struct repository *repo,\n+\t\t\t\t const struct replay_result *result,\n+\t\t\t\t struct commit **old_head,\n+\t\t\t\t struct commit **new_head,\n+\t\t\t\t bool *changed)\n+{\n+\tconst struct replay_ref_update *head_update = NULL;\n+\tstruct commit *old_head_commit, *new_head_commit;\n+\tstruct tree *old_head_tree, *new_head_tree;\n+\tconst char *head_target;\n+\tint head_flags;\n+\n+\t*changed = false;\n+\n+\thead_target = refs_resolve_ref_unsafe(get_main_ref_store(repo), \"HEAD\",\n+\t\t\t\t\t      RESOLVE_REF_NO_RECURSE | RESOLVE_REF_READING,\n+\t\t\t\t\t      NULL, &head_flags);\n+\tif (!head_target)\n+\t\treturn error(_(\"cannot look up HEAD\"));\n+\n+\tfor (size_t i = 0; i < result->updates_nr; i++) {\n+\t\tif (!strcmp(result->updates[i].refname, head_target)) {\n+\t\t\thead_update = &result->updates[i];\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (!head_update)\n+\t\treturn 0;\n+\n+\told_head_commit = lookup_commit_reference(repo, &head_update->old_oid);\n+\tnew_head_commit = lookup_commit_reference(repo, &head_update->new_oid);\n+\tif (!old_head_commit || !new_head_commit)\n+\t\treturn error(_(\"cannot resolve HEAD commit\"));\n+\n+\told_head_tree = repo_get_commit_tree(repo, old_head_commit);\n+\tnew_head_tree = repo_get_commit_tree(repo, new_head_commit);\n+\tif (!old_head_tree || !new_head_tree)\n+\t\treturn error(_(\"cannot resolve tree for HEAD\"));\n+\n+\tif (oideq(&old_head_tree->object.oid, &new_head_tree->object.oid))\n+\t\treturn 0;\n+\n+\t*old_head = old_head_commit;\n+\t*new_head = new_head_commit;\n+\t*changed = true;\n+\n+\treturn 0;\n+}\n+\n+static int cmd_history_drop(int argc,\n+\t\t\t    const char **argv,\n+\t\t\t    const char *prefix,\n+\t\t\t    struct repository *repo)\n+{\n+\tconst char * const usage[] = {\n+\t\tGIT_HISTORY_DROP_USAGE,\n+\t\tNULL,\n+\t};\n+\tenum replay_empty_commit_action empty = REPLAY_EMPTY_COMMIT_DROP;\n+\tenum ref_action action = REF_ACTION_DEFAULT;\n+\tint dry_run = 0;\n+\tstruct option options[] = {\n+\t\tOPT_CALLBACK_F(0, \"update-refs\", &action, \"(branches|head)\",\n+\t\t\t       N_(\"control which refs should be updated\"),\n+\t\t\t       PARSE_OPT_NONEG, parse_ref_action),\n+\t\tOPT_BOOL('n', \"dry-run\", &dry_run,\n+\t\t\t N_(\"perform a dry-run without updating any refs\")),\n+\t\tOPT_CALLBACK_F(0, \"empty\", &empty, \"(drop|keep|abort)\",\n+\t\t\t       N_(\"how to handle descendants that become empty\"),\n+\t\t\t       PARSE_OPT_NONEG, parse_opt_empty),\n+\t\tOPT_END(),\n+\t};\n+\tstruct strbuf reflog_msg = STRBUF_INIT;\n+\tstruct commit *original, *rewritten;\n+\tstruct rev_info revs = { 0 };\n+\tstruct replay_result result = { 0 };\n+\tstruct commit *old_head, *new_head;\n+\tbool head_moves = false;\n+\tint ret;\n+\n+\targc = parse_options(argc, argv, prefix, options, usage, 0);\n+\tif (argc != 1) {\n+\t\tret = error(_(\"command expects a single revision\"));\n+\t\tgoto out;\n+\t}\n+\trepo_config(repo, git_default_config, NULL);\n+\n+\tif (action == REF_ACTION_DEFAULT)\n+\t\taction = REF_ACTION_BRANCHES;\n+\n+\toriginal = lookup_commit_reference_by_name(argv[0]);\n+\tif (!original) {\n+\t\tret = error(_(\"commit cannot be found: %s\"), argv[0]);\n+\t\tgoto out;\n+\t}\n+\n+\tif (!original->parents) {\n+\t\tret = error(_(\"cannot drop root commit %s: \"\n+\t\t\t      \"it has no parent to replay onto\"),\n+\t\t\t    argv[0]);\n+\t\tgoto out;\n+\t} else if (original->parents->next) {\n+\t\tret = error(_(\"cannot drop merge commit: %s\"), argv[0]);\n+\t\tgoto out;\n+\t}\n+\n+\tret = setup_revwalk(repo, action, original, &revs);\n+\tif (ret)\n+\t\tgoto out;\n+\n+\trewritten = original->parents->item;\n+\n+\tret = compute_pending_ref_updates(&revs, action, original, rewritten,\n+\t\t\t\t\t  empty, &result);\n+\tif (ret) {\n+\t\tret = error(_(\"failed replaying descendants\"));\n+\t\tgoto out;\n+\t}\n+\n+\t/*\n+\t * If HEAD will move as a result of the rewrite then we'll have to\n+\t * merge in the changes into the worktree and index. This merge can of\n+\t * course conflict, which will cause the whole operation to abort.\n+\t *\n+\t * If we had already updated the refs at that point then we'd have an\n+\t * inconsistent repository state. So we first perform a dry-run merge\n+\t * here before updating refs.\n+\t */\n+\tif (!is_bare_repository()) {\n+\t\tret = find_head_tree_change(repo, &result, &old_head,\n+\t\t\t\t\t    &new_head, &head_moves);\n+\t\tif (ret < 0)\n+\t\t\tgoto out;\n+\n+\t\tif (head_moves && update_worktree(repo, old_head, new_head, true) < 0) {\n+\t\t\tret = error(_(\"dropping this commit would \"\n+\t\t\t\t      \"overwrite local changes; aborting\"));\n+\t\t\tgoto out;\n+\t\t}\n+\t}\n+\n+\tstrbuf_addf(&reflog_msg, \"drop: dropping %s\", argv[0]);\n+\tret = apply_pending_ref_updates(repo, &result, reflog_msg.buf, dry_run);\n+\tif (ret < 0) {\n+\t\tret = error(_(\"failed to update references\"));\n+\t\tgoto out;\n+\t}\n+\n+\tif (!dry_run && head_moves && update_worktree(repo, old_head, new_head, false) < 0) {\n+\t\tret = error(_(\"could not update working tree to new commit %s\"),\n+\t\t\t    oid_to_hex(&new_head->object.oid));\n+\t\tgoto out;\n+\t}\n+\n+\tret = 0;\n+\n+out:\n+\treplay_result_release(&result);\n+\tstrbuf_release(&reflog_msg);\n+\trelease_revisions(&revs);\n+\treturn ret;\n+}\n+\n int cmd_history(int argc,\n \t\tconst char **argv,\n \t\tconst char *prefix,\n \t\tstruct repository *repo)\n {\n \tconst char * const usage[] = {\n+\t\tGIT_HISTORY_DROP_USAGE,\n \t\tGIT_HISTORY_FIXUP_USAGE,\n \t\tGIT_HISTORY_REWORD_USAGE,\n \t\tGIT_HISTORY_SPLIT_USAGE,\n@@ -1012,6 +1195,7 @@ int cmd_history(int argc,\n \t};\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n+\t\tOPT_SUBCOMMAND(\"drop\", &fn, cmd_history_drop),\n \t\tOPT_SUBCOMMAND(\"fixup\", &fn, cmd_history_fixup),\n \t\tOPT_SUBCOMMAND(\"reword\", &fn, cmd_history_reword),\n \t\tOPT_SUBCOMMAND(\"split\", &fn, cmd_history_split),\ndiff --git a/t/meson.build b/t/meson.build\nindex 2af8d01279..d5e71056b2 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -399,6 +399,7 @@ integration_tests = [\n   't3451-history-reword.sh',\n   't3452-history-split.sh',\n   't3453-history-fixup.sh',\n+  't3454-history-drop.sh',\n   't3500-cherry.sh',\n   't3501-revert-cherry-pick.sh',\n   't3502-cherry-pick-merge.sh',\ndiff --git a/t/t3454-history-drop.sh b/t/t3454-history-drop.sh\nnew file mode 100755\nindex 0000000000..68a86d1e37\n--- /dev/null\n+++ b/t/t3454-history-drop.sh\n@@ -0,0 +1,561 @@\n+#!/bin/sh\n+\n+test_description='tests for git-history drop subcommand'\n+\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY/lib-log-graph.sh\"\n+\n+expect_graph () {\n+\tcat >expect &&\n+\tlib_test_cmp_graph --format=%s \"$@\"\n+}\n+\n+expect_log () {\n+\tgit log --format=\"%s\" \"$@\" >actual &&\n+\tcat >expect &&\n+\ttest_cmp expect actual\n+}\n+\n+test_expect_success 'errors on missing commit argument' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit initial &&\n+\t\ttest_must_fail git history drop 2>err &&\n+\t\ttest_grep \"command expects a single revision\" err\n+\t)\n+'\n+\n+test_expect_success 'errors on too many arguments' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit initial &&\n+\t\ttest_must_fail git history drop HEAD HEAD 2>err &&\n+\t\ttest_grep \"command expects a single revision\" err\n+\t)\n+'\n+\n+test_expect_success 'errors on unknown revision' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit initial &&\n+\t\ttest_must_fail git history drop does-not-exist 2>err &&\n+\t\ttest_grep \"commit cannot be found: does-not-exist\" err\n+\t)\n+'\n+\n+test_expect_success 'errors with invalid --empty= value' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit initial &&\n+\t\ttest_commit second &&\n+\t\ttest_must_fail git history drop --empty=bogus HEAD 2>err &&\n+\t\ttest_grep \"unrecognized.*--empty.*bogus\" err\n+\t)\n+'\n+\n+test_expect_success 'drops a commit in the middle and replays descendants' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\t\ttest_commit third &&\n+\n+\t\tgit symbolic-ref HEAD >expect &&\n+\t\tgit history drop HEAD~ &&\n+\t\tgit symbolic-ref HEAD >actual &&\n+\t\ttest_cmp expect actual &&\n+\n+\t\texpect_log <<-\\EOF &&\n+\t\tthird\n+\t\tfirst\n+\t\tEOF\n+\n+\t\ttest_must_fail git show HEAD:second.t &&\n+\t\ttest_path_is_missing second.t &&\n+\n+\t\tgit reflog >reflog &&\n+\t\ttest_grep \"drop: dropping HEAD~\" reflog\n+\t)\n+'\n+\n+test_expect_success 'drops the HEAD commit' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\n+\t\tgit history drop HEAD &&\n+\n+\t\texpect_log <<-\\EOF\n+\t\tfirst\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success 'drops a commit on detached HEAD' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\t\ttest_commit third &&\n+\t\tgit checkout --detach HEAD &&\n+\n+\t\tgit history drop HEAD~ &&\n+\n+\t\texpect_log <<-\\EOF\n+\t\tthird\n+\t\tfirst\n+\t\tEOF\n+\t)\n+'\n+\n+# Note: in this case it would actually be fine to drop the root commit, as we\n+# do have a descendant commit, and no reference points to the root commit\n+# directly. So this is something that we may relax eventually.\n+test_expect_success 'refuses to drop the root commit' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\n+\t\ttest_must_fail git history drop HEAD~ 2>err &&\n+\t\ttest_grep \"cannot drop root commit\" err\n+\t)\n+'\n+\n+# In contrast to the above case, we actually don't want to drop the root commit\n+# here as that would cause us to end up with an empty commit graph.\n+test_expect_success 'refuses to drop the root commit when branch becomes empty' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\n+\t\ttest_must_fail git history drop HEAD 2>err &&\n+\t\ttest_grep \"cannot drop root commit\" err\n+\t)\n+'\n+\n+test_expect_success 'refuses to drop a merge commit' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\tgit branch branch &&\n+\t\ttest_commit ours &&\n+\t\tgit switch branch &&\n+\t\ttest_commit theirs &&\n+\t\tgit switch - &&\n+\t\tgit merge theirs &&\n+\n+\t\ttest_must_fail git history drop HEAD 2>err &&\n+\t\ttest_grep \"cannot drop merge commit\" err\n+\t)\n+'\n+\n+test_expect_success 'refuses when descendants contain a merge commit' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\ttest_commit middle &&\n+\t\tgit branch branch &&\n+\t\ttest_commit ours &&\n+\t\tgit switch branch &&\n+\t\ttest_commit theirs &&\n+\t\tgit switch - &&\n+\t\tgit merge theirs &&\n+\n+\t\ttest_must_fail git history drop middle 2>err &&\n+\t\ttest_grep \"replaying merge commits is not supported yet\" err\n+\t)\n+'\n+\n+test_expect_success 'works in a bare repository' '\n+\ttest_when_finished \"rm -rf repo repo.git\" &&\n+\n+\tgit init repo &&\n+\ttest_commit -C repo first &&\n+\ttest_commit -C repo second &&\n+\ttest_commit -C repo third &&\n+\n+\tgit clone --bare repo repo.git &&\n+\t(\n+\t\tcd repo.git &&\n+\n+\t\tgit history drop HEAD~ &&\n+\t\texpect_log <<-\\EOF\n+\t\tthird\n+\t\tfirst\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success 'updates branches on other lines of descent' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\ttest_commit target &&\n+\t\tgit branch theirs &&\n+\t\ttest_commit ours &&\n+\t\tgit switch theirs &&\n+\t\ttest_commit theirs &&\n+\n+\t\texpect_graph --branches <<-\\EOF &&\n+\t\t* theirs\n+\t\t| * ours\n+\t\t|/\n+\t\t* target\n+\t\t* base\n+\t\tEOF\n+\n+\t\tgit history drop target &&\n+\n+\t\texpect_graph --branches <<-\\EOF\n+\t\t* ours\n+\t\t| * theirs\n+\t\t|/\n+\t\t* base\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success 'moves branch pointing at dropped commit to its parent' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo --initial-branch=main &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\t\tgit branch points-at-second &&\n+\t\ttest_commit third &&\n+\n+\t\tgit rev-parse first >expect &&\n+\t\tgit history drop second &&\n+\t\tgit rev-parse points-at-second >actual &&\n+\t\ttest_cmp expect actual &&\n+\n+\t\texpect_log --format=\"%s %D\" --branches <<-\\EOF\n+\t\tthird HEAD -> main\n+\t\tfirst tag: first, points-at-second\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success '--dry-run prints ref updates without modifying repo' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo --initial-branch=main &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\tgit branch branch &&\n+\t\ttest_commit middle &&\n+\t\ttest_commit ours &&\n+\t\tgit switch branch &&\n+\t\ttest_commit theirs &&\n+\n+\t\tgit refs list >refs-expect &&\n+\t\tgit history drop --dry-run main~ >updates &&\n+\t\tgit refs list >refs-actual &&\n+\t\ttest_cmp refs-expect refs-actual &&\n+\t\ttest_grep \"update refs/heads/main\" updates &&\n+\n+\t\tgit update-ref --stdin <updates &&\n+\t\texpect_log main <<-\\EOF\n+\t\tours\n+\t\tbase\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success '--dry-run detects conflicts with modified working tree' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo --initial-branch=main &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second modify-me &&\n+\t\techo modified >modify-me &&\n+\n+\t\tgit refs list >refs-expect &&\n+\t\tgit diff >diff-expect &&\n+\t\ttest_must_fail git history drop --dry-run HEAD 2>err &&\n+\t\ttest_grep \"dropping this commit would overwrite local changes\" err &&\n+\t\tgit diff >diff-actual &&\n+\t\tgit refs list >refs-actual &&\n+\n+\t\ttest_cmp diff-expect diff-actual &&\n+\t\ttest_cmp refs-expect refs-actual\n+\t)\n+'\n+\n+test_expect_success '--update-refs=head updates only HEAD' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo --initial-branch=main &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\ttest_commit target &&\n+\t\tgit branch theirs &&\n+\t\ttest_commit ours &&\n+\t\tgit switch theirs &&\n+\t\ttest_commit theirs &&\n+\n+\t\t# When told to update HEAD only, the command refuses to\n+\t\t# rewrite commits that are not an ancestor of HEAD.\n+\t\ttest_must_fail git history drop --update-refs=head main 2>err &&\n+\t\ttest_grep \"rewritten commit must be an ancestor of HEAD\" err &&\n+\n+\t\texpect_graph --branches <<-\\EOF &&\n+\t\t* theirs\n+\t\t| * ours\n+\t\t|/\n+\t\t* target\n+\t\t* base\n+\t\tEOF\n+\n+\t\tgit switch main &&\n+\t\tgit history drop --update-refs=head target &&\n+\n+\t\texpect_graph --branches <<-\\EOF\n+\t\t* ours\n+\t\t| * theirs\n+\t\t| * target\n+\t\t|/\n+\t\t* base\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success '--update-refs=head can rewrite detached HEAD' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo --initial-branch=main &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\t\ttest_commit third &&\n+\t\tgit switch --detach HEAD &&\n+\n+\t\tgit history drop --update-refs=head second &&\n+\n+\t\texpect_log HEAD <<-\\EOF &&\n+\t\tthird\n+\t\tfirst\n+\t\tEOF\n+\t\texpect_log main <<-\\EOF\n+\t\tthird\n+\t\tsecond\n+\t\tfirst\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success 'conflict with replayed commit aborts cleanly' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\ttest_commit conflict-a file &&\n+\t\ttest_commit conflict-b file &&\n+\n+\t\tgit refs list >refs-expect &&\n+\t\ttest_must_fail git history drop HEAD~ 2>err &&\n+\t\ttest_grep \"failed replaying descendants\" err &&\n+\t\tgit refs list >refs-actual &&\n+\t\ttest_cmp refs-expect refs-actual\n+\t)\n+'\n+\n+# Build a history where a descendant of the drop target reverts the change\n+# introduced by the drop target. After dropping, the descendant's diff applies\n+# against a tree that already lacks the change, so it becomes empty.\n+setup_empty_descendant_repo () {\n+\tgit init \"$1\" &&\n+\t(\n+\t\tcd \"$1\" &&\n+\t\techo C1 >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m \"base\" &&\n+\t\tgit tag base &&\n+\t\techo C2 >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m \"drop-me\" &&\n+\t\tgit tag drop-me &&\n+\t\ttest_commit middle &&\n+\t\techo C1 >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m \"revert-drop-me\" &&\n+\t\tgit tag revert-drop-me\n+\t)\n+}\n+\n+test_expect_success '--empty=drop drops descendants that become empty' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tsetup_empty_descendant_repo repo &&\n+\t(\n+\t\tcd repo &&\n+\n+\t\tgit history drop --empty=drop drop-me &&\n+\n+\t\texpect_log <<-\\EOF\n+\t\tmiddle\n+\t\tbase\n+\t\tEOF\n+\t)\n+'\n+\n+test_expect_success '--empty=keep keeps descendants that become empty' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tsetup_empty_descendant_repo repo &&\n+\t(\n+\t\tcd repo &&\n+\n+\t\tgit history drop --empty=keep drop-me &&\n+\n+\t\texpect_log <<-\\EOF &&\n+\t\trevert-drop-me\n+\t\tmiddle\n+\t\tbase\n+\t\tEOF\n+\t\tgit diff HEAD~ HEAD >diff &&\n+\t\ttest_must_be_empty diff\n+\t)\n+'\n+\n+test_expect_success '--empty=abort errors out when a descendant becomes empty' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tsetup_empty_descendant_repo repo &&\n+\t(\n+\t\tcd repo &&\n+\n+\t\ttest_must_fail git history drop --empty=abort drop-me 2>err &&\n+\t\ttest_grep \"became empty after replay\" err\n+\t)\n+'\n+\n+test_expect_success 'updates index and worktree when HEAD moves' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\t\ttest_commit third &&\n+\n+\t\tgit history drop second &&\n+\n+\t\t# Worktree should no longer contain second.t.\n+\t\ttest_path_is_missing second.t &&\n+\t\ttest_path_is_file first.t &&\n+\t\ttest_path_is_file third.t &&\n+\n+\t\t# Index and worktree should both match the new HEAD.\n+\t\tgit status --porcelain --untracked-files=no >status &&\n+\t\ttest_must_be_empty status\n+\t)\n+'\n+\n+test_expect_success 'updates worktree when dropping HEAD itself' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\ttest_commit second &&\n+\n+\t\tgit history drop HEAD &&\n+\n+\t\ttest_path_is_missing second.t &&\n+\t\ttest_path_is_file first.t &&\n+\n+\t\tgit status --porcelain --untracked-files=no >status &&\n+\t\ttest_must_be_empty status\n+\t)\n+'\n+\n+test_expect_success 'preserves unrelated unstaged modifications' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\techo first-content >unrelated.txt &&\n+\t\tgit add unrelated.txt &&\n+\t\tgit commit -m \"add unrelated\" &&\n+\t\ttest_commit second &&\n+\t\ttest_commit third &&\n+\n+\t\techo locally-modified >unrelated.txt &&\n+\n+\t\tgit diff >diff-expect &&\n+\t\tgit history drop second &&\n+\t\tgit diff >diff-actual &&\n+\t\ttest_cmp diff-expect diff-actual &&\n+\t\ttest_path_is_missing second.t\n+\t)\n+'\n+\n+test_expect_success 'preserves unrelated staged changes' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit first &&\n+\t\techo first-content >unrelated.txt &&\n+\t\tgit add unrelated.txt &&\n+\t\tgit commit -m \"add unrelated\" &&\n+\t\ttest_commit second &&\n+\t\ttest_commit third &&\n+\n+\t\techo staged-change >unrelated.txt &&\n+\t\tgit add unrelated.txt &&\n+\n+\t\tgit diff --cached >diff-expect &&\n+\t\tgit history drop second &&\n+\t\tgit diff --cached >diff-actual &&\n+\t\ttest_cmp diff-expect diff-actual &&\n+\t\ttest_path_is_missing second.t\n+\t)\n+'\n+\n+test_expect_success 'aborts when local modifications would be overwritten' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\ttest_commit base &&\n+\t\ttest_commit conflict &&\n+\n+\t\techo local-edit >conflict.t &&\n+\t\tgit diff >diff-expect &&\n+\t\ttest_must_fail git history drop HEAD 2>err &&\n+\t\ttest_grep \"would overwrite local changes\" err &&\n+\t\tgit diff >diff-actual &&\n+\t\ttest_cmp diff-expect diff-actual\n+\t)\n+'\n+\n+test_done\n\n-- \n2.55.0.795.g602f6c329a.dirty\n\n"},{"id":"546925","messageId":"xmqq1pdmprbk.fsf@gitster.g","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"Re: [PATCH v8 00/11] builtin/history: introduce \"drop\" subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-01T17:12:15Z","receivedAt":"2026-07-01T17:12:18Z","isPatch":true,"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Changes in v8:\n>   - Pass `RESOLVE_REF_READING` to make `refs_resolve_ref_unsafe()`\n>     return a NULL pointer when it cannot resolve the reference.\n\nOK.\n\n>   - Drop unneeded code that sets `head_target = \"HEAD\"` on detached\n>     HEAD.\n\nOK.\n\n>   - Add a test case that verifies that we can drop commits with\n>     \"--update-refs=head\" and a detached HEAD.\n\nOK.\n\nSounds good.  Will replace.\nThanks.\n"},{"id":"547040","messageId":"CAP8UFD3RZv=PGC15xms3xZZkNQsGLpgq_ogt8P9ux-8p4HwW6A@mail.gmail.com","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-6-19b5cdf1facd@pks.im","subject":"Re: [PATCH v8 06/11] reset: introduce ability to skip updating HEAD","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-07-03T06:59:30Z","receivedAt":"2026-07-03T06:59:44Z","isPatch":true,"body":"On Wed, Jul 1, 2026 at 1:35 PM Patrick Steinhardt <ps@pks.im> wrote:\n\n> @@ -113,6 +114,9 @@ int reset_working_tree(struct repository *r,\n>         if (opts->branch_msg && !opts->branch)\n>                 BUG(\"branch reflog message given without a branch\");\n>\n> +       if (update_orig_head && !update_head)\n> +               BUG(\"cannot update ORIG_HEAD without updating HEAD\" );\n\nThere is a spurious space character between `HEAD\"` and `);`.\n\n> +\n>         if (!refs_only && !dry_run && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {\n>                 ret = -1;\n>                 goto leave_reset_head;\n"},{"id":"547044","messageId":"CAP8UFD3OAktVQsLuqBNFH2uhEO31PH8ZF3ZT1ZW8k++XE8YLPw@mail.gmail.com","threadId":"65903","inReplyTo":"20260701-b4-pks-history-drop-v8-0-19b5cdf1facd@pks.im","subject":"Re: [PATCH v8 00/11] builtin/history: introduce \"drop\" subcommand","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-07-03T07:10:19Z","receivedAt":"2026-07-03T07:10:32Z","isPatch":true,"body":"On Wed, Jul 1, 2026 at 1:35 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> Hi,\n>\n> this small patch series introduces the new \"drop\" subcommand for\n> git-history(1). As a reader might guess, the command does exactly that:\n> given a commit, it will drop that commit from the commit history and\n> replay descendant branches on top of it.\n>\n> Changes in v8:\n>   - Pass `RESOLVE_REF_READING` to make `refs_resolve_ref_unsafe()`\n>     return a NULL pointer when it cannot resolve the reference.\n>   - Drop unneeded code that sets `head_target = \"HEAD\"` on detached\n>     HEAD.\n>   - Add a test case that verifies that we can drop commits with\n>     \"--update-refs=head\" and a detached HEAD.\n>   - Link to v7: https://patch.msgid.link/20260629-b4-pks-history-drop-v7-0-6e9392a957d8@pks.im\n\nExcept for the style nit in patch 6 (spurious space character), this\nseries looks good to me.\n\nThanks.\n"},{"id":"547049","messageId":"akd14OKLT9lAMKTf@pks.im","threadId":"65903","inReplyTo":"CAP8UFD3RZv=PGC15xms3xZZkNQsGLpgq_ogt8P9ux-8p4HwW6A@mail.gmail.com","subject":"Re: [PATCH v8 06/11] reset: introduce ability to skip updating HEAD","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-07-03T08:42:08Z","receivedAt":"2026-07-03T08:42:15Z","isPatch":true,"body":"On Fri, Jul 03, 2026 at 08:59:30AM +0200, Christian Couder wrote:\n> On Wed, Jul 1, 2026 at 1:35 PM Patrick Steinhardt <ps@pks.im> wrote:\n> \n> > @@ -113,6 +114,9 @@ int reset_working_tree(struct repository *r,\n> >         if (opts->branch_msg && !opts->branch)\n> >                 BUG(\"branch reflog message given without a branch\");\n> >\n> > +       if (update_orig_head && !update_head)\n> > +               BUG(\"cannot update ORIG_HEAD without updating HEAD\" );\n> \n> There is a spurious space character between `HEAD\"` and `);`.\n\nUgh, indeed, well spotted. Junio, is this something you can fix up or\nshall I send a new version for this?\n\nPatrick\n"},{"id":"547109","messageId":"xmqqwlvchta8.fsf@gitster.g","threadId":"65903","inReplyTo":"akd14OKLT9lAMKTf@pks.im","subject":"Re: [PATCH v8 06/11] reset: introduce ability to skip updating HEAD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-03T17:33:51Z","receivedAt":"2026-07-03T17:33:54Z","isPatch":true,"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Fri, Jul 03, 2026 at 08:59:30AM +0200, Christian Couder wrote:\n>> On Wed, Jul 1, 2026 at 1:35 PM Patrick Steinhardt <ps@pks.im> wrote:\n>> \n>> > @@ -113,6 +114,9 @@ int reset_working_tree(struct repository *r,\n>> >         if (opts->branch_msg && !opts->branch)\n>> >                 BUG(\"branch reflog message given without a branch\");\n>> >\n>> > +       if (update_orig_head && !update_head)\n>> > +               BUG(\"cannot update ORIG_HEAD without updating HEAD\" );\n>> \n>> There is a spurious space character between `HEAD\"` and `);`.\n>\n> Ugh, indeed, well spotted. Junio, is this something you can fix up or\n> shall I send a new version for this?\n\nI just locally updated it, so no need to resend the whole series, as\nthere does not seem to be any other issues.\n\nThanks, all.\n"},{"id":"547114","messageId":"xmqqik6vj0zr.fsf@gitster.g","threadId":"65903","inReplyTo":"CAP8UFD3OAktVQsLuqBNFH2uhEO31PH8ZF3ZT1ZW8k++XE8YLPw@mail.gmail.com","subject":"Re: [PATCH v8 00/11] builtin/history: introduce \"drop\" subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-03T20:02:00Z","receivedAt":"2026-07-03T20:02:04Z","isPatch":true,"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n>> Changes in v8:\n>>   - Pass `RESOLVE_REF_READING` to make `refs_resolve_ref_unsafe()`\n>>     return a NULL pointer when it cannot resolve the reference.\n>>   - Drop unneeded code that sets `head_target = \"HEAD\"` on detached\n>>     HEAD.\n>>   - Add a test case that verifies that we can drop commits with\n>>     \"--update-refs=head\" and a detached HEAD.\n>>   - Link to v7: https://patch.msgid.link/20260629-b4-pks-history-drop-v7-0-6e9392a957d8@pks.im\n>\n> Except for the style nit in patch 6 (spurious space character), this\n> series looks good to me.\n\nThanks.\n"}]}