192

I have a couple of Git repositories that belong together, and simple batch/Bash file to loop over them. I often loop over them with a log command to quickly see what state they are in. This works nicely, except for one thing: if the commit message is longer than the number of characters my console is wide (or has multiple lines), Git shows the line, then a newline with (END), and I have to press Q to continue (I guess it pipes the output through more or something like that).

Example:

> gitloop . "git log --decorate=short --pretty=oneline -n1"
18629ae238e9d5832cb3535ec88274173337a501 (HEAD, origin/master, master) short log

625fb891b9b0b8648459b07ace662ae3b7773c7f (HEAD, origin/master, origin/HEAD, master) short log

dc0838118266ba8570ea338c1faddfe8af0387bb (HEAD, origin/work, origin/master, work, master) oops loooooooooooooong log
-(END)

This is rather inconvenient as I have to press Q a couple of time, whereas I'd just like to see all those one-liner programs in one go.

How can I disable this behaviour (preferably while still keeping this log format)?

2
  • 4
    possible duplicate of why do I have to hit q at the end of git log Commented Dec 19, 2012 at 9:13
  • Thanks, the SEO worked and I found this! My main use case is different: I want to scroll back in terminal and be able to see the commit hashes from where I was the last time I ran git log. For some reason the Page prevents this in iTerm. The answers here all worked. Great. Commented Jan 8, 2022 at 22:57

7 Answers 7

295

Git has an option to disable the pager:

git --no-pager log --decorate=short --pretty=oneline -n1

If your pager cuts lines and you want to retain that behaviour, either pipe to cut...

git --no-pager log --decorate=short --pretty=oneline -n1 | cut -c 1-$COLUMNS

...or set the environment variable GIT_PAGER before the invocation:

GIT_PAGER="cut -c 1-${COLUMNS-80}" git log --decorate=short --pretty=oneline -n1
Sign up to request clarification or add additional context in comments.

6 Comments

Is there a way to make --no-pager the default or even better at a shortcut for this option when needed ? I thought of aliasing gitnp to git --no-pager, but I think there is a better solution.
@IslamAzab, you could alias git to /usr/bin/git --no-pager which would disable the pager for all your git calls.
@WarrenP git does not have built in pager. Instead, it follows Unix philosophy and uses whatever you have in $PAGER. git simply always uses $PAGER instead of doing that only randomly unlike many other poorly written tools. The only magic git has is that if $LESS is not defined, it will define $LESS to value FRX. See around github.com/git/git/blob/master/Documentation/config.txt#L766 for more details.
Simplest case that fixes the behavior just for git: export GIT_PAGER=cat
@IslamAzab -P is an alias for --no-pager, for example, git -P log -1 --name-only.
|
57

Another solution for the problem of permanently disabling pager specifically when using log subcommand:

  • for current repo only:
    git config pager.log false

  • for your git installation (i. e. all repos on your machine):
    git config --global pager.log false

As you can guess, the same works if pager is needed to be on or off for some other subcommands selectively.
E. g. for branch (which prints branches) subcommand it will be

git config pager.branch false


Proposed solution is arguably more elegant comparing to

  • using git --no-pager each time you run certain command.
    Because, quite possible, you don't want to type it each time.

  • specifying git --no-pager as an alias for git
    Because, quite possible, you want to avoid implicit global config OR you want pager to be enabled in some cases.

  • rely on some environment variables like PAGER or GIT_PAGER.
    Because to do that, you need to ensure they're set in your current terminal session. And, if you want them to be set to some custom value automatically each time your new terminal is created, you need to alter one of shell-bootstrapped files like e. g. ~/.bashrc. It's not a big problem. But these bootstrapped files frequently are altered by other applications as well and contain bunch of other stuff, not just that used by Git. So, in theory, it's better to specify git-related settings using git config rather than put them in e. g. ~/.bashrc.


The alternative solution for disabling pager for all subcommands is to specify cat as the utility git will use for paging:

  • git config core.pager cat OR
  • git config --global core.pager cat

My answer is somewhat rephrasing of the one below:
"prevent git diff from using a pager?"
https://stackoverflow.com/a/6986231/6103242

It's referenced to point out another relevant discussion.

3 Comments

Once I do this is it possible to do something like git --pager log when I actually want it from time to time?
@Arsen I don't think it's directly supported. git help log page does not have any mention about pager as an option. What you can do though is to add custom wrapper-function in ~/.zshrc or ~/.bashrc file so it does 3 things: switches the pager ON, executes git log, switches the pager OFF. gitLogWithPager() { git config pager.log true; git log ${@}; git config pager.log false; } Reopen your terminal and then you should be able to use gitLogWithPager command. ${@} forwards any additional arguments to git log.
This is the most helpful answer, think it should be the accepted one
9

Disable pager for all commands:

git config --global core.pager '' 

1 Comment

This works great! On Windows + Powershell use (double quotes inside single quotes): git config --global core.pager '""'
5
export PAGER=cat

worked for me

1 Comment

I really like that solution since piping log to cat doesn't preserve the colors of the log output but exporting cat into PAGER still results in a colorful output. Thanks for pointing that out. Though I just found out about the --no-pager option which I also like, I think. :-)
3

Although the above answers are probably correct, I would like add one that suites me best. I recommend configure less instead of git by adding the following flags:

export LESS="${LESS:+$LESS }-X -F"
-X  Disables sending the termcap initialization and deinitialization strings to the terminal.
-F or --quit-if-one-screen -> no need to press `q` if output fits into the current terminal size.

Comments

3

You pipe it to less -F in case --no-pager does not work for you.

git log --decorate --oneline -5 | less -F

-F means that less will behave like --no-pager if the output fits on one screen, but become a pager otherwise.

2 Comments

That still paginates, though. Piping it to cat would avoid that.
Piping to cat is ideal if you have a bash alias like alias glo="git log --color=always --pretty=tformat:'%C(brightblue)%h %C(white)%as %C(cyan)%an %C(green)%d %C(reset)%s'"
-1

If the requirement is to see the log in the terminal itself and quit, without opening the editor, we can use:

export PAGER=cat command

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.