32

When I was using Git Bash (Git For Windows) if a command (like git diff) had a short output (I'm guessing smaller than the terminal's height) it would just print as output, now in Babun (Cygwin) every Git command seems to be viewed in less even if it's one line or completely empty. "Every" is perhaps too bold, git status doesn't. It just seems like there was some pre-bundled setting in one of these that the other doesn't have and I don't know what it is.

How can I make Git behave so that when there is a short output it doesn't use less and instead just outputs it.

Edit: In git bash my pager for git is 'less -x4' (for 4 width tabs), no -F. Also, the environment variables LESS, PAGER, and GIT_PAGER are empty. So I have no idea why git bash is behaving like this, but luckily I've gotten some help on how to make Babun (Cygwin) start.

Hindsight update: (This is probably wrong, see 2017-01-12 note.) I think that Git For Windows and/or the default terminal doesn't wipe the screen when closing less -- I saw this behavior somewhere else that was unrelated (closing less and the screen not being wiped) so I think that's what is happening. Why Cygwin and the mintty terminal does the wipe and MINGW (or Msys2? Whatever Git For Windows uses) on the Windows terminal does not is beyond my realm of knowledge.

Hindsight update post Googling: Turns out the above revelation was enough info to Google the solution! I will post it now.

2017-01-12: Looks like it wasn't wiping it precisely because LESS was unset. According to man git config...

core.pager
    [...]

    When the LESS environment variable is unset, Git sets it to FRX
    (if LESS environment variable is set, Git does not change it at
    all). If you want to selectively override Git’s default setting
    for LESS, you can set core.pager to e.g.  less -S. This will be
    passed to the shell by Git, which will translate the final
    command to LESS=FRX less -S. [...]
kdb
  • 4,098
  • 26
  • 49
Captain Man
  • 6,997
  • 6
  • 48
  • 74

5 Answers5

32

As of December 2017 if you are using the latest version of less (at least 530) then the below is slightly incorrect. Now -F alone will properly output short output (as if by cat) while not needing -X. Since you can now use -F alone to see short output this means long output will still be properly wiped from the screen once you close less! I highly recommend you update your version of less to get this behavior. It's great!


Schwern's answer is half correct. For what I was asking it is probably still the correct answer, I was just using the incorrect words. What I wanted wasn't this:

   -F or --quit-if-one-screen
          Causes less to automatically exit if the entire file can be dis‐
          played on the first screen.

That makes nothing appear for short output! If core.pager is less -F and your log is less than one screen, you see nothing.

What you probably want is less -FX or maybe less -X.

   -X or --no-init
          Disables sending the termcap initialization and deinitialization
          strings  to  the  terminal.   This is sometimes desirable if the
          deinitialization string does something unnecessary, like  clear‐
          ing the screen.

This question over at superuser led me to this.

Using -FX if the log is less than one screen then it just outputs it (as if by cat).

Using only -X will still open less if the output is less than one screen but will leave it on the terminal if you quit, if you don't quit right away you can actually use less like normal. Once you try to search though it brings it into "real" less and still does not wipe when done, which is annoying because the windows is now full of ~'s.


Summary

  • If you don't care what happens with short output, use less
  • If you have an older version of less than 530 and you want short output to be put on the screen as if by cat use less -XF
    • If you have version 530 or newer then just use less -F. See the top of the answer for more info.
  • If you want to perhaps search short output (even though it's less than one screen) then use less -X, but you will have to still press q.
Captain Man
  • 6,997
  • 6
  • 48
  • 74
6

Quick answer: Save the following line to your .bashrc

export LESS=eFRX

The whys and wherefores are covered in the answers to How do I prevent git diff from using a pager? where the OP is actually looking to remove pagination completely.

Robino
  • 4,530
  • 3
  • 37
  • 40
3

You could configure git to use cat as the pager (instead of less).

git config --global core.pager cat

This will add the section

[core]
    pager = cat

to your ~/.gitconfig file and pipe everything through cat, i.e. just display it.

It's discussed here How do I prevent git diff from using a pager? in more detail.

Community
  • 1
  • 1
PerlDuck
  • 5,610
  • 3
  • 20
  • 39
  • 2
    Will this cause `git` to use `cat` as its pager for **every** command? – Code-Apprentice Feb 05 '16 at 20:58
  • 1
    "-F to less will tell it to not page if the output fits in a single screen." This sounds like setting the pager to `less -F` will more accurately answer this question. – Code-Apprentice Feb 05 '16 at 21:00
  • @Code-Apprentice: Yes, except that `git ... --help` will still use a pager. (I have that setting; I use an explicit `git ... | less` when I want to.) – Keith Thompson Feb 05 '16 at 21:01
  • @Code-Apprentice Yes. That's the downside. I like it that way, but perhaps the solutions given in the link I provided are more fine grained. – PerlDuck Feb 05 '16 at 21:01
  • I've voted to close as a dupe since it appears that the Q you linked provides the answer. – Code-Apprentice Feb 05 '16 at 21:03
  • @Code-Apprentice Sure. If I'd known how to do that I'd done it too. I'm quite new as an active SO member :-) – PerlDuck Feb 05 '16 at 21:07
  • Ahh...you probably don't have enough rep yet to close questions. Welcome to SO and thanks for your contributions ;-) – Code-Apprentice Feb 05 '16 at 21:08
3

You can do this to keep LESS for all git output but always return if there is only 1 page, no exports needed.

git config --global core.pager 'less -F'
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48
0

This is not a Git thing, it's a property of your pager. Git doesn't know how long the output is going to be so it will always output using your pager.

Configure your pager to quit if your output is less than one full screen. With less that's -F. You can set the LESS environment variable with your default switches.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • Are there any other environment variables that define this? `LESS` is empty for me and my `core.pager` is `less -x4` so I'm just trying to figure out why it's doing this (not that its relevant). – Captain Man Feb 05 '16 at 21:25
  • @CaptainMan The default behavior of `less` is to always page. You have to set `-F` if you want it to not page for output that's less than a page. It's my understanding you want the second behavior, so set `-F` somewhere. – Schwern Feb 05 '16 at 21:34
  • Right, what I am now curious about is why less in my git bash behaves like this despite not having that `-F` flag anywhere. – Captain Man Feb 05 '16 at 22:29
  • 1
    @CaptainMan That I don't know. `less` doesn't have a config file that I can find, so command line switches and environment variables are the only way to configure it. The only other explanation is Git Bash changed the default behavior of `less` or it's just different on Windows. – Schwern Feb 05 '16 at 22:47
  • Actually, this behavior is different. This causes less to exit, but whatever git bash is doing causes it do 'cat', using `less -F` simply does nothing (visibly at least) with short output – Captain Man Feb 06 '16 at 02:06