本文介绍了防止git使用分页器输出短消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Git Bash(适用于Windows的Git)时,如果某个命令(如git diff)的输出很短(我猜是小于终端的高度),它将仅打印为输出,现在显示为 Babun (Cygwin)似乎每条Git命令的浏览量都更少,即使它是一行或完全为空. 每个"都可能太粗体,git status并非如此.似乎其中一个具有一些预捆绑的设置,而另一个则没有,我也不知道它是什么.

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.

如何使Git表现良好,以便在输出短时不会少用,而只是输出它.

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

在git bash中,我的git pager是'less -x4'(用于4个宽度的制表符),没有-F.此外,环境变量LESSPAGERGIT_PAGER为空.所以我不知道为什么git bash会这样,但是幸运的是我在如何使Babun(Cygwin)启动方面获得了一些帮助.

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更新:(这可能是错误的,请参阅2017年1月12日的注释.)我认为Git For Windows和/或默认终端在关闭较少时不会擦拭屏幕- -我在其他无关的地方看到了此行为(关闭次数减少,屏幕没有擦拭),所以我认为这是正在发生的事情.为什么Cygwin和mintty终端在Windows终端上进行擦拭和MINGW(或Msys2?无论Windows使用什么Git)都不在我的知识范围之外.

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在谷歌搜索后的最新更新:事实证明,上述启示足以为Google解决方案提供信息!我现在将其发布.

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

2017-01-12:似乎没有完全擦除它,因为 LESS未设置.根据man git config ...

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. [...]

推荐答案

截至2017年12月您使用的是最新版本的less(至少530),则以下内容略有错误. 现在,仅-F就能正确输出简短的输出(就像),而无需-X.由于现在您可以单独使用-F来查看简短的输出,这意味着 long 的输出在您关闭less之后仍然会从屏幕上正确擦除!我高度建议您更新您的less版本以实现此行为.太好了!

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的答案是正确的一半.对于我所问的可能仍然是正确答案的问题,我只是使用了不正确的单词.我想要的不是这个吗?

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.

这使得一无所有不会出现短输出!如果core.pagerless -F,并且您的日志少于一个屏幕,则看不到任何内容.

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

您可能想要的是less -FXless -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.

如果日志少于一个屏幕,则使用-FX,它只会输出日志(就像cat一样).

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

如果输出少于一个屏幕,则仅使用-X仍会打开less,但如果您 uit而不是 uit,您实际上可以像平常一样使用less.一旦您尝试搜索,尽管它使它带入了真实"的空间,并且完成后仍然不会擦除,但是这很烦人,因为窗口现在充满了~.

Using only -X will still open less if the output is less than one screen but will leave it on the terminal if you uit, if you don't uit 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.

  • 如果您不关心输出短时会发生什么,请使用less
  • 如果您的less版本比530还要旧,并且希望将短输出显示在屏幕上,就像cat一样,请使用less -XF
    • 如果您具有530或更高版本,则只需使用less -F.有关更多信息,请参见答案顶部.
    • 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.

      这篇关于防止git使用分页器输出短消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 11:41