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

[PATCH v4 0/2] reflog: add format %gb

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 4, 2026, 21:15 UTC
Message-ID
<pull.2448.v4.git.git.1793826938.gitgitgadget@gmail.com>
In-Reply-To
<pull.2448.git.git.1792070038.gitgitgadget@gmail.com>

Create a better reflog. Follows the discussion in https://lore.kernel.org/git/akZfm-igZKeHaDST@pks.im/.

The reflog of HEAD records the work done on every branch, so "git reflog" mixes them and does not say which entry was made on which branch. This adds a "%gb" placeholder that names the branch HEAD was on when each entry was recorded:

$ git log -g --format='%h %gd: (%gb) %gs' 9c8d7e6 HEAD@{0}: (topic) rebase (finish): returning to refs/heads/topic 1a2b3c4 HEAD@{2}: (topic) rebase (start): checkout main 1a2b3c4 HEAD@{3}: (main) commit: fix typo

It follows branch switches, branch renames and rebases, including "git rebase ", rebases of a detached HEAD and rebases of a branch that was already up to date. When HEAD was detached, the entry shows "detached at ".

Changes in v4:
 * %gb now names the right branch when git rebase <upstream> <branch> runs
   with GIT_REFLOG_ACTION set.
 * Reworded the %gb commit message.
Changes in v3:
 * Dropped --operations.
 * Replaced --historical-branch with a %gb placeholder for --format, e.g.
   git log -g --format='%h %gd: (%gb) %gs'.
 * %gb names the right branch after git rebase <upstream> <branch>, a rebase
   of a detached HEAD and an up-to-date rebase.
 * Named the returning to and checkout reflog strings in reflog.h too.
Changes in v2:
 * Move the "historical branch" rightward in the display for cleaner
   alignment.
 * Improve commit messages.
Harald Nordgren (2):
  reflog: name the strings that mark switches, renames and rebase steps
  pretty: add %gb to name the branch of each reflog entry
 Documentation/pretty-formats.adoc |   3 +
 builtin/branch.c                  |   3 +-
 builtin/checkout.c                |   3 +-
 builtin/rebase.c                  |  19 ++--
 object-name.c                     |   3 +-
 pretty.c                          |   4 +
 reflog-walk.c                     | 167 ++++++++++++++++++++++++++++--
 reflog-walk.h                     |   2 +
 reflog.h                          |   8 ++
 sequencer.c                       |  13 +--
 t/t1414-reflog-walk.sh            | 137 ++++++++++++++++++++++++
 wt-status.c                       |   3 +-
 12 files changed, 340 insertions(+), 25 deletions(-)
base-commit: 750f5de7dfe9a4062f95088212b063f189d50e91
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2448%2FHaraldNordgren%2Freflog-operations-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2448/HaraldNordgren/reflog-operations-v4
Pull-Request: https://github.com/git/git/pull/2448
Range-diff vs v3:
 1:  4d779e8da3 = 1:  f960a24b8b reflog: name the strings that mark switches, renames and rebase steps
 2:  dee548f9b1 ! 2:  99a1047702 pretty: add %gb to name the branch of each reflog entry
     @@ Commit message
              1a2b3c4 HEAD@{3}: (main) commit: fix typo
              5d6e7f8 HEAD@{4}: (main) checkout: moving from topic to main
      
     -    The branch is read from the entries that branch switches, branch
     -    renames and rebases leave behind. The entries of a rebase are named
     -    after the branch being rebased. When HEAD was detached, the entry
     -    shows "detached at <commit>" with the commit HEAD was at when it
     -    moved on. When nothing older in the reflog says which branch a rebase
     -    started on, the rebase is taken to have started on the branch it
     -    rebased. For the reflog of any other ref, "%gb" is the name of that
     -    ref.
     +    The branch is read from the entries created by branch switches,
     +    branch renames and rebases. The entries of a rebase are labeled with
     +    the branch being rebased. When HEAD was detached, the entry shows
     +    "detached at <commit>" with the commit HEAD was at when it moved on.
     +    When nothing older in the reflog says which branch a rebase started
     +    on, the rebase is taken to have started on the branch it rebased. For
     +    the reflog of any other ref, "%gb" is the name of that ref.
      
          Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
      
     @@ reflog-walk.c: static void complete_reflogs_clear(void *util, const char *str UN
      +	return p;
      +}
      +
     ++static const char *skip_rebase_checkout(const char *message)
     ++{
     ++	const char *p = strstr(message, " (");
     ++	const char *colon = strstr(message, ": ");
     ++
     ++	if (!colon || (p && p < colon) ||
     ++	    !skip_prefix(colon + 2, REFLOG_CHECKOUT, &p))
     ++		return NULL;
     ++	return p;
     ++}
     ++
      +struct branch_move {
      +	const char *from, *to;
      +	size_t from_len, to_len;
     @@ reflog-walk.c: static void complete_reflogs_clear(void *util, const char *str UN
      +		   skip_prefix(to, REFLOG_RETURNING_TO, &to)) {
      +		move->from = move->to = to;
      +		move->from_len = strcspn(to, "\n");
     -+	} else if (skip_prefix(message, "rebase: " REFLOG_CHECKOUT, &to)) {
     ++	} else if ((to = skip_rebase_checkout(message))) {
      +		move->to = to;
      +	} else if (!skip_rebase_step(message, REFLOG_STEP_START)) {
      +		return false;
     @@ t/t1414-reflog-walk.sh: test_expect_success 'walk prefers reflog to ref tip' '
      +	)
      +'
      +
     ++test_expect_success '%gb follows "git rebase <upstream> <branch>" with GIT_REFLOG_ACTION' '
     ++	(
     ++		cd branches &&
     ++		git switch main &&
     ++		GIT_REFLOG_ACTION="sync switch" git rebase main topic &&
     ++
     ++		cat >expect <<-\EOF &&
     ++		(topic) sync switch: checkout topic
     ++		(main) checkout: moving from topic to main
     ++		EOF
     ++		git log -g -2 --format="(%gb) %gs" >actual &&
     ++		test_cmp expect actual
     ++	)
     ++'
     ++
      +test_expect_success '%gb names a detached HEAD by the commit it was left at' '
      +	(
      +		cd branches &&
-- 
gitgitgadget
Previous: Phillip WoodNext: Harald Nordgren via GitGitGadget
Message 44 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.