17

I created a Git alias based off of the Git Immersion tutorial by EdgeCase that looks like this:

hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

But now it seems to be paging the results — Terminal shows (END) after the results are displayed, forcing me to hit Q to continue working. I read that by adding in the --no-pager tag, you can disable this feature; how do I incorporate it into the alias? I've tried it at the end, before the log, and right after, and none of them have worked. Git throws an error saying it is an unrecognized argument, or that it changes environment variables. Any advice?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Ian
  • 237
  • 2
  • 5
  • You really don't want to do this, though. Once you get to using a git project with a sizable history, the log will be *very* long. – asmeurer Jul 10 '13 at 04:20

3 Answers3

26

You can do that easily by just turning it into a shell command:

hist = "!git --no-pager log ..."
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Cascabel
  • 479,068
  • 72
  • 370
  • 318
8

Note: with Git 2.18 (Q2 2018), the alias can use a shorter option for --no-pager:
"git --no-pager cmd" did not have short-and-sweet single letter option. Now it does.

The alias can now be:

hist = "!git -P log ..."

See commit 7213c28 (03 May 2018) by Johannes Sixt (j6t).
(Merged by Junio C Hamano -- gitster -- in commit c9aac55, 23 May 2018)

git: add -P as a short option for --no-pager

It is possible to configure 'less', the pager, to use an alternate screen to show the content, for example, by setting LESS=RS in the environment.
When it is closed in this configuration, it switches back to the original screen, and all content is gone.

It is not uncommon to request that the output remains visible in the terminal. For this, the option --no-pager can be used.
But it is a bit cumbersome to type, even when command completion is available.
Provide a short option, -P, to make the option more easily accessible.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • in scripts I would prefer writing it out to make it easier to comprehend. When using it on the CLI this is of course still useful. – xeruf Jun 03 '20 at 13:35
  • @Xerus I agree: no for script, yes for CLI. – VonC Jun 03 '20 at 13:37
4

The --no-pager option gives an unrecognized option error when used after log, but it worked by putting --no-pager before log - "git --no-pager log .... " worked

Munir
  • 2,548
  • 1
  • 11
  • 20
  • partial solution is nice - with this approach git does not use a pager for the given command. However, it terminates prematurely with two other messages... #1 - error: warning: exhaustive rename detection was skipped due to too many files. #2 - warning: you may want to set your diff.renameLimit variable to at least 3072 and retry the command. – Kay V Jan 06 '22 at 19:16