2

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)?

Brent Faust
  • 9,103
  • 6
  • 53
  • 57

3 Answers3

3

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Good advice to use `--pretty`. Although the output of "full" is a bit verbose, it points the way to a possible solution using the other --pretty formatting options. – Brent Faust May 04 '14 at 15:19
  • 1
    @Rubistro "a possible solution using the other `--pretty` formatting options": which I edited in my answer just after your edit of your question. – VonC May 04 '14 at 15:20
  • Ah... yes. still doesn't wrap, though. – Brent Faust May 04 '14 at 15:21
  • @Rubistro even with core.pager option? – VonC May 04 '14 at 15:22
  • Yes, as the core.pager option does something, but messes up the first line (in OS X terminal, anyway). Great tip on using the left and right arrows to see the overflow (even without the core.pager setting), but in this particular case, I'm looking for a way to see everything wrapped on the single screen without flipping to the right and back. – Brent Faust May 04 '14 at 15:29
2

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.)

Brent Faust
  • 9,103
  • 6
  • 53
  • 57
1

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.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • Beautiful. Although to make this the default behavior (using git config) in git 1.8.5.2, I had to use the form: `+-S`, i.e.: `git config --global core.pager "less -+S` – Brent Faust May 06 '14 at 22:24