Skip to content

pr-git-2448/HaraldNordgren/reflog-operations-v5

tagged this 07 Nov 11:55
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 v5:

 * detached at <commit> now names the commit HEAD was detached at, or for a
   detached rebase, the commit it ended on.
 * git rebase <upstream> <rev> counts <rev> as a branch only if
   refs/heads/<rev> exists, so origin/main and refs/heads/main show as
   detached.
 * A commit whose subject starts with checkout is no longer taken for a
   rebase checkout.
 * Added Phillip's test, and tests for a detached rebase that fast-forwards
   and one that is aborted.

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                     | 217 +++++++++++++++++++++++++++-
 reflog-walk.h                     |   2 +
 reflog.h                          |   9 ++
 sequencer.c                       |  15 +-
 t/t1414-reflog-walk.sh            | 229 ++++++++++++++++++++++++++++++
 wt-status.c                       |   3 +-
 12 files changed, 484 insertions(+), 26 deletions(-)

base-commit: fb255012acbcbe81189cb8014da0280b09c66ecc

Submitted-As: https://lore.kernel.org/git/pull.2448.v5.git.git.1794052536.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2448.git.git.1792070038.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2448.v2.git.git.1792348037.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2448.v3.git.git.1793090327.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2448.v4.git.git.1793826938.gitgitgadget@gmail.com
Assets 2
Loading