Captain Man Captain Man - 2 months ago 10
Git Question

Git diff it always outputting into less even if it's small or no output

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.

Hind-sight update: 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.

Hind-sight update post Googling: Turns out the above revalation was enough info to Google the solution! I will post it now.

Answer

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 not full of ~'s.


Summary

  • If you don't care what happens with short output, use less
  • If you want short output to be put on the screen as if by cat use less -XF
  • 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.
Comments