Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make git log produce command output 'inline'

Tags:

git

logging

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?

like image 839
deshmukh Avatar asked May 08 '17 10:05

deshmukh


People also ask

What is the output of git log?

By default, git log includes merge commits in its output. But, if your team has an always-merge policy (that is, you merge upstream changes into topic branches instead of rebasing the topic branch onto the upstream branch), you'll have a lot of extraneous merge commits in your project history.

What happens when you execute git log command?

The git log command shows a list of all the commits made to a repository. You can see the hash of each Git commit , the message associated with each commit, and more metadata. This command is useful for displaying the history of a repository.

What is git log Oneline?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message.

Does git log show all branches?

Graph all git branches Developers can see all branches in the graph with the –all switch. Also, in most situations, the –decorate switch will provide all the supplemental information in a formatted and nicely color-coded way. The Git log graph a dog mnemonic.


1 Answers

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.

like image 112
eush77 Avatar answered Sep 21 '22 13:09

eush77