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

[PATCH v4 06/10] reset: introduce ability to skip updating HEAD

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 10, 2026, 08:52 UTC
Message-ID
<20260610-b4-pks-history-drop-v4-6-70d5f0ae8c25@pks.im>
In-Reply-To
<20260610-b4-pks-history-drop-v4-0-70d5f0ae8c25@pks.im>

In a subsequent commit we'll introduce a new caller to `reset_working_tree()` that really only wants to update the index and working tree, without updating any references. Introduce a new flag that makes the caller opt in to updating HEAD and adapt all callers to set that flag.

Note that in a previous iteration we instead introduced a flag that made callers opt out of updating any references. This was somewhat awkward though because we already have the `UPDATE_ORIG_HEAD` flag, so the result was somewhat inconsistent.

Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/rebase.c | 14 ++++++++++----
 reset.c          |  6 ++++--
 reset.h          |  9 ++++++---
 sequencer.c      |  4 +++-
 4 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 06dcbaf5e8..10a306310c 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -607,7 +607,8 @@ static int move_to_original_branch(struct rebase_options *opts)
 	strbuf_addf(&head_reflog, "%s (finish): returning to %s",
 		    opts->reflog_action, opts->head_name);
 	ropts.branch = opts->head_name;
-	ropts.flags = RESET_WORKING_TREE_REFS_ONLY;
+	ropts.flags = RESET_WORKING_TREE_REFS_ONLY |
+		      RESET_WORKING_TREE_UPDATE_HEAD;
 	ropts.branch_msg = branch_reflog.buf;
 	ropts.head_msg = head_reflog.buf;
 	ret = reset_working_tree(the_repository, &ropts);
@@ -693,6 +694,7 @@ static int run_am(struct rebase_options *opts)
 		ropts.oid = &opts->orig_head->object.oid;
 		ropts.branch = opts->head_name;
 		ropts.default_reflog_action = opts->reflog_action;
+		ropts.flags = RESET_WORKING_TREE_UPDATE_HEAD;
 		reset_working_tree(the_repository, &ropts);
 		error(_("\ngit encountered an error while preparing the "
 			"patches to replay\n"
@@ -862,7 +864,8 @@ static int checkout_up_to_date(struct rebase_options *options)
 		    options->reflog_action, options->switch_to);
 	ropts.oid = &options->orig_head->object.oid;
 	ropts.branch = options->head_name;
-	ropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;
+	ropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK |
+		      RESET_WORKING_TREE_UPDATE_HEAD;
 	if (!ropts.branch)
 		ropts.flags |=  RESET_WORKING_TREE_DETACH;
 	ropts.head_msg = buf.buf;
@@ -1384,7 +1387,8 @@ int cmd_rebase(int argc,
 
 		rerere_clear(the_repository, &merge_rr);
 		string_list_clear(&merge_rr, 1);
-		ropts.flags = RESET_WORKING_TREE_HARD;
+		ropts.flags = RESET_WORKING_TREE_HARD |
+			      RESET_WORKING_TREE_UPDATE_HEAD;
 		if (reset_working_tree(the_repository, &ropts) < 0)
 			die(_("could not discard worktree changes"));
 		remove_branch_state(the_repository, 0);
@@ -1409,7 +1413,8 @@ int cmd_rebase(int argc,
 		ropts.oid = &options.orig_head->object.oid;
 		ropts.head_msg = head_msg.buf;
 		ropts.branch = options.head_name;
-		ropts.flags = RESET_WORKING_TREE_HARD;
+		ropts.flags = RESET_WORKING_TREE_HARD |
+			      RESET_WORKING_TREE_UPDATE_HEAD;
 		if (reset_working_tree(the_repository, &ropts) < 0)
 			die(_("could not move back to %s"),
 			    oid_to_hex(&options.orig_head->object.oid));
@@ -1877,6 +1882,7 @@ int cmd_rebase(int argc,
 	ropts.oid = &options.onto->object.oid;
 	ropts.orig_head = &options.orig_head->object.oid;
 	ropts.flags = RESET_WORKING_TREE_DETACH |
+		      RESET_WORKING_TREE_UPDATE_HEAD |
 		      RESET_WORKING_TREE_UPDATE_ORIG_HEAD |
 		      RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;
 	ropts.head_msg = msg.buf;
diff --git a/reset.c b/reset.c
index 99f2c1b012..3ac99a51c0 100644
--- a/reset.c
+++ b/reset.c
@@ -92,6 +92,7 @@ int reset_working_tree(struct repository *r,
 	const char *switch_to_branch = opts->branch;
 	unsigned reset_hard = opts->flags & RESET_WORKING_TREE_HARD;
 	unsigned refs_only = opts->flags & RESET_WORKING_TREE_REFS_ONLY;
+	unsigned update_head = opts->flags & RESET_WORKING_TREE_UPDATE_HEAD;
 	unsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD;
 	unsigned dry_run = opts->flags & RESET_WORKING_TREE_DRY_RUN;
 	struct object_id *head = NULL, head_oid;
@@ -129,7 +130,7 @@ int reset_working_tree(struct repository *r,
 		oid = &head_oid;
 
 	if (refs_only) {
-		if (!dry_run)
+		if (update_head)
 			return update_refs(r, opts, oid, head);
 		return 0;
 	}
@@ -197,7 +198,8 @@ int reset_working_tree(struct repository *r,
 		goto leave_reset_head;
 	}
 
-	if (oid != &head_oid || update_orig_head || switch_to_branch)
+	if (update_head &&
+	    (oid != &head_oid || update_orig_head || switch_to_branch))
 		ret = update_refs(r, opts, oid, head);
 
 leave_reset_head:
diff --git a/reset.h b/reset.h
index 898e4a1e95..38b2891b53 100644
--- a/reset.h
+++ b/reset.h
@@ -19,14 +19,17 @@ enum reset_working_tree_flags {
 	/* Only update refs, do not touch the worktree */
 	RESET_WORKING_TREE_REFS_ONLY = (1 << 3),
 
-	/* Update ORIG_HEAD as well as HEAD */
-	RESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 4),
+	/* Update HEAD */
+	RESET_WORKING_TREE_UPDATE_HEAD = (1 << 4),
+
+	/* Update ORIG_HEAD */
+	RESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 5),
 
 	/*
 	 * Perform a dry-run by performing the operation without updating
 	 * any user-visible state.
 	 */
-	RESET_WORKING_TREE_DRY_RUN = (1 << 5),
+	RESET_WORKING_TREE_DRY_RUN = (1 << 6),
 };
 
 struct reset_working_tree_options {
diff --git a/sequencer.c b/sequencer.c
index 4efe831178..e905b1b2d9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4678,7 +4678,8 @@ static void create_autostash_internal(struct repository *r,
 	    has_uncommitted_changes(r, 1)) {
 		struct child_process stash = CHILD_PROCESS_INIT;
 		struct reset_working_tree_options ropts = {
-			.flags = RESET_WORKING_TREE_HARD,
+			.flags = RESET_WORKING_TREE_HARD |
+				 RESET_WORKING_TREE_UPDATE_HEAD,
 		};
 		struct object_id oid;
 
@@ -4873,6 +4874,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
 		.oid = onto,
 		.orig_head = orig_head,
 		.flags = RESET_WORKING_TREE_DETACH |
+			 RESET_WORKING_TREE_UPDATE_HEAD |
 			 RESET_WORKING_TREE_UPDATE_ORIG_HEAD |
 			 RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK,
 		.head_msg = reflog_message(opts, "start", "checkout %s",
-- 
2.54.0.1189.g8c84645362.dirty
Previous: Patrick SteinhardtNext: Phillip Wood
Message 52 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.