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

[PATCH 1/3] reflog: name the strings that mark switches, renames and rebase steps

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 15, 2026, 13:13 UTC
Message-ID
<d95ed5bd679cea41320c39824b969377e8c88e09.1792070038.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2448.git.git.1792070038.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>

"git checkout" records a move of HEAD in the reflog as "checkout: moving from <old> to <new>", "git branch -m" records a rename of the current branch as "Branch: renamed <old> to <new>", and "git rebase" marks where it starts and ends with steps like "rebase (start)" and "rebase (finish)". "@{-<n>}" and "git status" read the switch message back, each with its own copy of the prefix, and a later commit adds a reader for all of them.

Name these strings in reflog.h and use them where the messages are written and read, so they cannot drift apart.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 builtin/branch.c   |  3 ++-
 builtin/checkout.c |  3 ++-
 builtin/rebase.c   | 17 +++++++++--------
 object-name.c      |  3 ++-
 reflog.h           |  6 ++++++
 sequencer.c        | 13 +++++++------
 wt-status.c        |  3 ++-
 7 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index a613148fc7..30062ceb7c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -13,6 +13,7 @@
 #include "editor.h"
 #include "environment.h"
 #include "refs.h"
+#include "reflog.h"
 #include "commit.h"
 #include "gettext.h"
 #include "object-name.h"
@@ -669,7 +670,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
 		strbuf_addf(&logmsg, "Branch: copied %s to %s",
 			    oldref.buf, newref.buf);
 	else
-		strbuf_addf(&logmsg, "Branch: renamed %s to %s",
+		strbuf_addf(&logmsg, REFLOG_RENAME_PREFIX "%s to %s",
 			    oldref.buf, newref.buf);
 
 	if (!copy && !(oldref_usage & IS_ORPHAN) &&
diff --git a/builtin/checkout.c b/builtin/checkout.c
index c0f0d2c700..9f0f09e50f 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -25,6 +25,7 @@
 #include "preload-index.h"
 #include "read-cache.h"
 #include "refs.h"
+#include "reflog.h"
 #include "remote.h"
 #include "repo-settings.h"
 #include "resolve-undo.h"
@@ -999,7 +1000,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 
 	reflog_msg = getenv("GIT_REFLOG_ACTION");
 	if (!reflog_msg)
-		strbuf_addf(&msg, "checkout: moving from %s to %s",
+		strbuf_addf(&msg, REFLOG_SWITCH_PREFIX "%s to %s",
 			old_desc ? old_desc : "(invalid)", new_branch_info->name);
 	else
 		strbuf_insertstr(&msg, 0, reflog_msg);
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 535db60181..26ef589e89 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -17,6 +17,7 @@
 #include "strvec.h"
 #include "dir.h"
 #include "refs.h"
+#include "reflog.h"
 #include "config.h"
 #include "unpack-trees.h"
 #include "lockfile.h"
@@ -601,11 +602,11 @@ static int move_to_original_branch(struct rebase_options *opts)
 	if (!opts->onto)
 		BUG("move_to_original_branch without onto");
 
-	strbuf_addf(&branch_reflog, "%s (finish): %s onto %s",
-		    opts->reflog_action,
+	strbuf_addf(&branch_reflog, "%s (%s): %s onto %s",
+		    opts->reflog_action, REFLOG_STEP_FINISH,
 		    opts->head_name, oid_to_hex(&opts->onto->object.oid));
-	strbuf_addf(&head_reflog, "%s (finish): returning to %s",
-		    opts->reflog_action, opts->head_name);
+	strbuf_addf(&head_reflog, "%s (%s): returning to %s",
+		    opts->reflog_action, REFLOG_STEP_FINISH, opts->head_name);
 	ropts.branch = opts->head_name;
 	ropts.flags = RESET_WORKING_TREE_REFS_ONLY |
 		      RESET_WORKING_TREE_UPDATE_HEAD;
@@ -1413,8 +1414,8 @@ int cmd_rebase(int argc,
 		if (read_basic_state(&options))
 			exit(1);
 
-		strbuf_addf(&head_msg, "%s (abort): returning to %s",
-			    options.reflog_action,
+		strbuf_addf(&head_msg, "%s (%s): returning to %s",
+			    options.reflog_action, REFLOG_STEP_ABORT,
 			    options.head_name ? options.head_name
 					      : oid_to_hex(&options.orig_head->object.oid));
 		ropts.oid = &options.orig_head->object.oid;
@@ -1884,8 +1885,8 @@ int cmd_rebase(int argc,
 		printf(_("First, rewinding head to replay your work on top of "
 			 "it...\n"));
 
-	strbuf_addf(&msg, "%s (start): checkout %s",
-		    options.reflog_action, options.onto_name);
+	strbuf_addf(&msg, "%s (%s): checkout %s", options.reflog_action,
+		    REFLOG_STEP_START, options.onto_name);
 	ropts.oid = &options.onto->object.oid;
 	ropts.orig_head = &options.orig_head->object.oid;
 	ropts.flags = RESET_WORKING_TREE_DETACH |
diff --git a/object-name.c b/object-name.c
index 4eda8c8eac..bb349014ee 100644
--- a/object-name.c
+++ b/object-name.c
@@ -13,6 +13,7 @@
 #include "tree.h"
 #include "tree-walk.h"
 #include "refs.h"
+#include "reflog.h"
 #include "remote.h"
 #include "dir.h"
 #include "odb.h"
@@ -1251,7 +1252,7 @@ static int grab_nth_branch_switch(const char *refname UNUSED,
 	const char *match = NULL, *target = NULL;
 	size_t len;
 
-	if (skip_prefix(message, "checkout: moving from ", &match))
+	if (skip_prefix(message, REFLOG_SWITCH_PREFIX, &match))
 		target = strstr(match, " to ");
 
 	if (!match || !target)
diff --git a/reflog.h b/reflog.h
index 3bdd1ca8a5..32c3737db4 100644
--- a/reflog.h
+++ b/reflog.h
@@ -2,6 +2,12 @@
 #define REFLOG_H
 #include "refs.h"
 
+#define REFLOG_SWITCH_PREFIX "checkout: moving from "
+#define REFLOG_RENAME_PREFIX "Branch: renamed "
+#define REFLOG_STEP_START "start"
+#define REFLOG_STEP_FINISH "finish"
+#define REFLOG_STEP_ABORT "abort"
+
 #define REFLOG_EXPIRE_TOTAL   (1 << 0)
 #define REFLOG_EXPIRE_UNREACH (1 << 1)
 
diff --git a/sequencer.c b/sequencer.c
index efbfd1315b..c55df2d38f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -31,6 +31,7 @@
 #include "merge-ort.h"
 #include "merge-ort-wrappers.h"
 #include "refs.h"
+#include "reflog.h"
 #include "sparse-index.h"
 #include "strvec.h"
 #include "quote.h"
@@ -5011,8 +5012,8 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
 			 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",
-					   onto_name),
+		.head_msg = reflog_message(opts, REFLOG_STEP_START,
+					   "checkout %s", onto_name),
 		.default_reflog_action = sequencer_reflog_action(opts)
 	};
 	if (reset_working_tree(r, &ropts)) {
@@ -5310,16 +5311,16 @@ cleanup_head_ref:
 				res = error(_("could not read 'onto'"));
 				goto cleanup_head_ref;
 			}
-			msg = reflog_message(opts, "finish", "%s onto %s",
-				head_ref.buf, buf.buf);
+			msg = reflog_message(opts, REFLOG_STEP_FINISH,
+				"%s onto %s", head_ref.buf, buf.buf);
 			if (refs_update_ref(get_main_ref_store(the_repository), msg, head_ref.buf, &head, &orig,
 					    REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
 				res = error(_("could not update %s"),
 					head_ref.buf);
 				goto cleanup_head_ref;
 			}
-			msg = reflog_message(opts, "finish", "returning to %s",
-				head_ref.buf);
+			msg = reflog_message(opts, REFLOG_STEP_FINISH,
+				"returning to %s", head_ref.buf);
 			if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", head_ref.buf, msg)) {
 				res = error(_("could not update HEAD to %s"),
 					head_ref.buf);
diff --git a/wt-status.c b/wt-status.c
index 57772c7501..ffd54353a8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -22,6 +22,7 @@
 #include "strvec.h"
 #include "remote.h"
 #include "refs.h"
+#include "reflog.h"
 #include "submodule.h"
 #include "column.h"
 #include "read-cache.h"
@@ -1790,7 +1791,7 @@ static int grab_1st_switch(const char *refname UNUSED,
 	struct grab_1st_switch_cbdata *cb = cb_data;
 	const char *target = NULL, *end;
 
-	if (!skip_prefix(message, "checkout: moving from ", &message))
+	if (!skip_prefix(message, REFLOG_SWITCH_PREFIX, &message))
 		return 0;
 	target = strstr(message, " to ");
 	if (!target)
-- 
gitgitgadget
Previous: Harald Nordgren via GitGitGadgetNext: Kristoffer Haugsbakk
Message 2 of 51 in “reflog: add --operations and --historical-branch”
  1. 0/3 reflog: add --operations and --historical-branchHarald Nordgren via GitGitGadget, Oct 15, 2026
  2. 1/3 reflog: name the strings that mark switches, renames and rebase stepsHarald Nordgren via GitGitGadget, Oct 15, 2026
  3. Kristoffer HaugsbakkOct 15, 2026
  4. Harald NordgrenOct 15, 2026
  5. 2/3 reflog: add --operations to show one entry per commandHarald Nordgren via GitGitGadget, Oct 15, 2026
  6. 3/3 reflog: add --historical-branch to name the branch of each entryHarald Nordgren via GitGitGadget, Oct 15, 2026
  7. Kristoffer HaugsbakkOct 15, 2026
  8. Harald NordgrenOct 15, 2026
  9. Kristoffer HaugsbakkOct 15, 2026
  10. Harald NordgrenOct 15, 2026
  11. D. Ben KnobleOct 16, 2026
  12. Harald NordgrenOct 23, 2026
  13. D. Ben KnobleOct 16, 2026
  14. Harald NordgrenOct 17, 2026
  15. 0/3 reflog: add --operations and --historical-branchHarald Nordgren via GitGitGadget, Oct 18, 2026
  16. 1/3 reflog: name the strings that mark switches, renames and rebase stepsHarald Nordgren via GitGitGadget, Oct 18, 2026
  17. Junio C HamanoOct 23, 2026
  18. Harald NordgrenOct 23, 2026
  19. Junio C HamanoOct 23, 2026
  20. 2/3 reflog: add --operations to show one entry per commandHarald Nordgren via GitGitGadget, Oct 18, 2026
  21. 3/3 reflog: add --historical-branch to name the branch of each entryHarald Nordgren via GitGitGadget, Oct 18, 2026
  22. Kristoffer HaugsbakkOct 25, 2026
  23. Harald NordgrenOct 25, 2026
  24. Kristoffer HaugsbakkOct 26, 2026
  25. Harald NordgrenOct 26, 2026
  26. Harald NordgrenOct 23, 2026
  27. Phillip WoodOct 24, 2026
  28. D. Ben KnobleOct 24, 2026
  29. Junio C HamanoOct 24, 2026
  30. Harald NordgrenOct 24, 2026
  31. Kristoffer HaugsbakkOct 25, 2026
  32. Phillip WoodOct 26, 2026
  33. Harald NordgrenOct 26, 2026
  34. Junio C HamanoOct 26, 2026
  35. Ben KnobleOct 27, 2026
  36. Junio C HamanoOct 27, 2026
  37. Harald NordgrenOct 27, 2026
  38. Ben KnobleOct 27, 2026
  39. Harald NordgrenOct 24, 2026
  40. 0/2 reflog: add --operations and --historical-branchHarald Nordgren via GitGitGadget, Oct 27, 2026
  41. 1/2 reflog: name the strings that mark switches, renames and rebase stepsHarald Nordgren via GitGitGadget, Oct 27, 2026
  42. 2/2 pretty: add %gb to name the branch of each reflog entryHarald Nordgren via GitGitGadget, Oct 27, 2026
  43. Phillip WoodNov 3, 2026
  44. 0/2 reflog: add format %gbHarald Nordgren via GitGitGadget, Nov 4, 2026
  45. 1/2 reflog: name the strings that mark switches, renames and rebase stepsHarald Nordgren via GitGitGadget, Nov 4, 2026
  46. 2/2 pretty: add %gb to name the branch of each reflog entryHarald Nordgren via GitGitGadget, Nov 4, 2026
  47. Phillip WoodNov 6, 2026
  48. Harald NordgrenNov 7, 2026
  49. 0/2 reflog: add format %gbHarald Nordgren via GitGitGadget, Nov 7, 2026
  50. 1/2 reflog: name the strings that mark switches, renames and rebase stepsHarald Nordgren via GitGitGadget, Nov 7, 2026
  51. 2/2 pretty: add %gb to name the branch of each reflog entryHarald Nordgren via GitGitGadget, Nov 7, 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.