deshmukh
deshmukh

Reputation: 383

Make git log produce command output 'inline'

I do not know how to better word this.

When I run any git log command, it produces an output in a 'window' of its own. I need to hit q to come back to the prompt and then all the log display is gone.

Is there any way to produce the log output 'inline' so the log output is displayed followed by the prompt?

Upvotes: 19

Views: 7078

Answers (2)

Rajendra Dangwal
Rajendra Dangwal

Reputation: 227

use the following command:

git log | cat

The output of git log will be shown on terminal by cat.

Upvotes: 21

eush77
eush77

Reputation: 4088

The reason the output of git log does not stay in the terminal history after git exits is that the pager program git uses to display its output emits escape sequences to switch to the alternate display buffer to keep the main buffer intact. This is usually a useful feature.

Some pagers allow to disable this buffer switching. For example, if the pager is less (the default one on Unix-like systems), you can set LESS environment variable in your shell config file:

export LESS="--no-init"

This will turn -X, --no-init option on by default (which can then be turned off by a -+X switch on the command line). The effect is that the output of git log will be written in the main buffer, and as a result stay in the terminal history.

If the pager supports buffer switching, but does not have a way to turn it off, then the only solution is not to use such a pager for git log output.

Switch the pager to something else:

$ git config --global core.pager less

Or disable paging for git log:

$ git config --global pager.log false

Or even completely — for every other git command:

$ git config --global core.pager cat

When I run any git log command, it produces an output in a 'window' of its own. I need to hit q to come back to the prompt

As for this part of your question, I'd say that you don't actually want megabytes of git log output be spilled in your terminal every time you run git log. Features pagers provide you with are generally very useful: scrolling, searching, jumping, changing files, running commands and so on.

What you probably want is to bypass the pager for short output. git does not provide this functionality, but some pagers do. For example, if you're using less, you can add -F, --quit-if-one-screen option to LESS environment variable in your shell config:

export LESS="--no-init --quit-if-one-screen"

This will make less exit automatically if the entire output can be displayed in a single screen.

Upvotes: 29

Related Questions