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

[PATCH v8 4/7] replay: yield the object ID of the final rewritten commit

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 7, 2026, 10:10 UTC
Message-ID
<20260107-b4-pks-history-builtin-v8-4-18e9779e3a26@pks.im>
In-Reply-To
<20260107-b4-pks-history-builtin-v8-0-18e9779e3a26@pks.im>

In a subsequent commit we'll introduce a new git-history(1) command that uses the replay machinery to rewrite commits. One of its supported modes will only want to update the "HEAD" reference, but that is not currently supported by the replay machinery.

Allow implementing this use case by exposing a `final_oid` field for the reference updates. This field will be set to the last commit that was rewritten, which is sufficient information for us to implement this mode in git-history(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 replay.c |  2 ++
 replay.h | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
diff --git a/replay.c b/replay.c
index 367951395a..8c2f2d3710 100644
--- a/replay.c
+++ b/replay.c
@@ -330,6 +330,8 @@ int replay_revisions(struct repository *repo, struct rev_info *revs,
 		updates->nr++;
 	}
 
+	updates->final_oid = last_commit->object.oid;
+
 	ret = 0;
 
 out:
diff --git a/replay.h b/replay.h
index bc7a321a5e..e00bb4214e 100644
--- a/replay.h
+++ b/replay.h
@@ -43,6 +43,22 @@ struct replay_ref_updates {
 		struct object_id new_oid;
 	} *items;
 	size_t nr, alloc;
+
+	/*
+	 * The final object ID that was rewritten. Note that this field has
+	 * somewhat special semantics and may or may not be what you want:
+	 *
+	 *   - If no commits were rewritten it will remain uninitialized.
+	 *
+	 *   - If a thicket of branches is rewritten it is undefined in which
+	 *     order those branches will be rewritten, and thus the final object
+	 *     ID may point to a different commit than you'd expect.
+	 *
+	 * That being said, this field can still be useful when you know that
+	 * you only replay a single strand of commits. In that case, the final
+	 * commit will point to the tip of the rewritten strand of commits.
+	 */
+	struct object_id final_oid;
 };
 
 void replay_ref_updates_release(struct replay_ref_updates *updates);
-- 
2.52.0.542.g9473a8513b.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 7 of 18 in “Introduce git-history(1) command for easy history editing”
  1. 0/7 Introduce git-history(1) command for easy history editingPatrick Steinhardt, Jan 7, 2026
  2. 1/7 builtin/replay: extract core logic to replay revisionsPatrick Steinhardt, Jan 7, 2026
  3. D. Ben KnobleJan 7, 2026
  4. Patrick SteinhardtJan 9, 2026
  5. 2/7 builtin/replay: move core logic into "libgit.a"Patrick Steinhardt, Jan 7, 2026
  6. 3/7 replay: small set of cleanupsPatrick Steinhardt, Jan 7, 2026
  7. 4/7 replay: yield the object ID of the final rewritten commitPatrick Steinhardt, Jan 7, 2026
  8. 5/7 wt-status: provide function to expose status for treesPatrick Steinhardt, Jan 7, 2026
  9. 6/7 builtin: add new "history" commandPatrick Steinhardt, Jan 7, 2026
  10. 7/7 builtin/history: implement "reword" subcommandPatrick Steinhardt, Jan 7, 2026
  11. D. Ben KnobleJan 7, 2026
  12. Patrick SteinhardtJan 9, 2026
  13. D. Ben KnobleJan 9, 2026
  14. Elijah NewrenJan 10, 2026
  15. Patrick SteinhardtJan 12, 2026
  16. D. Ben KnobleJan 7, 2026
  17. Patrick SteinhardtJan 9, 2026
  18. D. Ben KnobleJan 9, 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.