Disable "buffered view" when display 'git' commands results

479 views Asked by At

I just switched to a new (already configured) development box.

Now git behaves differently, with some commands.

Let me try to explain it:

  • before (on the other machine) when typing git log I was getting the list of commits in my terminal. So I could just scroll up and copy/past SHAs as many times as I wanted.

  • now (on the new machine) when typing git log I get a new buffer in the terminal, where I'm shown the commits. Now I have to exit/quit the result display pressing Q. After that the buffer is cleared and I come back to the terminal, but I DO NOT have any logged/buffered result in it; so I CAN NOT scroll up to see the result of the command.

To be more clear, now many git commands (diff, log, reflog, show, etc.) behave like vim or man, where the output of the command is in a separate buffer and the user explicitly needs to exit this view to come back to the shell.

Is that some kind of git configuration? Maybe a specified default editor? Or maybe is a operative system setting?

I was not able to find information (or the right keywords for searching the information) for solving this issue.

1

There are 1 answers

0
Kamafeather On BEST ANSWER

I hope this will be useful to others (and more easy to find with non-specific search keywords!). The solution seems to be about setting the pager of git.

The pager is the command that is used to display the git commands output.

In my case trying to run:

git config -l

was not showing me any evidence of the current setting. But coming from a previous version I just assume that the default value for the pager has been changed to something different from less recently. And with the new pager the screen is cleared after pressing Q, not allowing the the terminal buffer to maintain the output result.

Anyway I was more comfortable with the old pager: less, or no pager at all.

So I reset it with the command:

git config --global core.pager ''

This will use no pager and will always show the output in the shell, allowing you to scroll up and copy/paste/check any part of the git commands output. But is not nice whith git log because it will scroll down to the end of the list and will show the less recent commits.

So the perfect solution (for me) was to set it to less, BUT ADDITIONALLY I had to pass some options to it for defining the exact desired behaviour; so now I'm shown the list from the top, and then I can scroll up and see everything I output.

The final command I used is:

git config --global core.pager 'less -FRSX'

(as explained on the section Better pager defaults of this Atlassian documentation page)

The fundamental in those settings is -X that prevents the screen from being cleared. While -R allows to maintain a colored output.