Wrap Long git reflog Lines?

436 Views Asked by At

git reflog displays a single-line description, clipping it at the right margin.

74a8491 HEAD@{0}: checkout: moving from feature/x to feature/y
74a8491 HEAD@{1}: commit (merge): Merge branch 'feature/x' of https://github.com/
949d0e4 HEAD@{2}: ...

How can the entire reflog message be displayed, wrapped to take the minimum lines necessary (single-line for short descriptions)?

3

There are 3 best solutions below

5
VonC On

git reflog can take any git log option you want.

If you want the full commit message associate with each git reflog entries, you can do a:

git reflog show --pretty=full

Or, for the "single-line for short descriptions"

git reflog show --pretty=format:"%h : %s"

You can force a wrap for long messages with the core.pager config.

1
Brent Faust On

To emulate 'git reflog', adding the author, time ago date, and wrap long description lines:

git reflog show --pretty='%C(yellow)%h%Creset %gd %w(110,0,26)%gs %C(cyan)%cn%Creset %ar'
  • %h is the short hash
  • %w(wrapwidth, firstLineIndent, indent) causes the next field to be wrapped to the given width
  • %gs is the reflog description
  • %cn is the committer's name
  • %ar is the date of the change in relative format (time ago)

Make it permanent:

To enable the command:

git r     # call it whatever you want

Put this into the ~/.gitconfig file:

[alias] r = reflog show --pretty='%C(yellow)%h%Creset %gd %w(110,0,26)%gs %C(cyan)%cn%Creset %ar'

(The alias can be named anything other than 'reflog' or an existing command.)

1
jthill On

The usual pager is less, and you can toggle its line-wrapping option. Type -S at the pager prompt. h will give more gory details.