From: Harald Nordgren via GitGitGadget Date: Sat, 07 Nov 2026 11:55:36 GMT Subject: [PATCH v5 2/2] pretty: add %gb to name the branch of each reflog entry Message-ID: <34bb9309088b2ff9252d22456b504c3e20b63bef.1794052536.git.gitgitgadget@gmail.com> In-Reply-To: From: Harald Nordgren The reflog of HEAD records the work done on every branch, so the output of "git reflog" mixes them and does not say which entry was made on which branch. Working that out by hand means looking back for the branch switch before each entry, and a rebase can move HEAD to another branch without writing one, as "git rebase " does. 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 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 " with the commit HEAD was detached at, or for a rebase of a detached HEAD the commit the rebase ended on. These entries only record what was typed, so when no newer entry says otherwise, a name counts as a branch if a branch of that name exists. 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 --- Documentation/pretty-formats.adoc | 3 + pretty.c | 4 + reflog-walk.c | 217 +++++++++++++++++++++++++++- reflog-walk.h | 2 + t/t1414-reflog-walk.sh | 229 ++++++++++++++++++++++++++++++ 5 files changed, 449 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++`[: