From: Phillip Wood Date: Tue, 03 Nov 2026 16:16:54 GMT Subject: Re: [PATCH v3 2/2] pretty: add %gb to name the branch of each reflog entry Message-ID: <49144eb0-9755-4843-930e-ae7b3b519080@gmail.com> In-Reply-To: Hi Harald On 27/10/2026 08:38, Harald Nordgren via GitGitGadget wrote: > From: Harald Nordgren > > Add 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 > 9c8d7e6 HEAD@{1}: (topic) rebase (pick): add tests > 1a2b3c4 HEAD@{2}: (topic) rebase (start): checkout main > 1a2b3c4 HEAD@{3}: (main) commit: fix typo > 5d6e7f8 HEAD@{4}: (main) checkout: moving from topic to main Looks good > The branch is read from the entries that branch switches, branch > renames and rebases leave behind. "the entries created by ..."? > The entries of a rebase are named > after the branch being rebased. This sounds very LLM, "labelled with the branch being rebased"? > When HEAD was detached, the entry > shows "detached at " with the commit HEAD was at when it > moved on. I wondered if that was a bit verbose, but having tried it, it is no longer than some of my branch names. > 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. I'm seeing some strange behavior when GIT_REFLOG_ACTION is set, below is the output of "git reflog --format='%h %gd %gs (%gb)'" for my local HEAD. I've added comments above the lines where the branch name is incorrect. The "sync switch" entries come from running "git rebase" with GIT_REFLOG_ACTION set. be8e0d55ec HEAD@{0} reset: moving to HEAD (sequencer-delete-REBASE_HEAD) be8e0d55ec HEAD@{1} sync switch: checkout sequencer-delete-REBASE_HEAD (sequencer-delete-REBASE_HEAD) # should be fix-nth-prior-checkout 64822b4a3b HEAD@{2} sync switch: checkout fix-nth-prior-checkout (sequencer-delete-REBASE_HEAD) # should be detached at 64882b4a3b 64822b4a3b HEAD@{3} rebase: fast-forward (sequencer-delete-REBASE_HEAD) # should be detached at 64822b4a3b bf19b60d89 HEAD@{4} rebase (start): checkout @^ (sequencer-delete-REBASE_HEAD) 64822b4a3b HEAD@{5} rebase: fast-forward (detached at 64822b4a3b) bf19b60d89 HEAD@{6} rebase (start): checkout fix-nth-prior-checkout^ (detached at 64822b4a3b) be8e0d55ec HEAD@{7} rebase: checkout sequencer-delete-REBASE_HEAD (sequencer-delete-REBASE_HEAD) be8e0d55ec HEAD@{8} rebase (start): checkout sequencer-delete-REBASE_HEAD (detached at be8e0d55ec) 64822b4a3b HEAD@{9} checkout: moving from 64822b4a3ba71e5a823002cd5ebe0fa5fb4b3a0c to fix-nth-prior-checkout (fix-nth-prior-checkout) Thanks Phillip > Signed-off-by: Harald Nordgren > --- > Documentation/pretty-formats.adoc | 3 + > pretty.c | 4 + > reflog-walk.c | 156 ++++++++++++++++++++++++++++-- > reflog-walk.h | 2 + > t/t1414-reflog-walk.sh | 122 +++++++++++++++++++++++ > 5 files changed, 281 insertions(+), 6 deletions(-) > > diff --git a/Documentation/pretty-formats.adoc b/Documentation/pretty-formats.adoc > index 2ae0eb11a9..a8d00397c4 100644 > --- a/Documentation/pretty-formats.adoc > +++ b/Documentation/pretty-formats.adoc > @@ -334,6 +334,9 @@ endif::git-rev-list[] > +%gE+:: reflog identity email (respecting .mailmap, see > linkgit:git-shortlog[1] or linkgit:git-blame[1]) > +%gs+:: reflog subject > ++%gb+:: reflog branch, the branch `HEAD` was on when the entry was > + recorded, e.g., `topic` or `detached at 1a2b3c4`. For the reflog > + of any other ref, this is the shortened refname. > ++%(trailers++`[: