Git 列表命令有时会模拟多页终端,但我希望输出始终转储到标准输出

Git list commands sometimes emulate a multi-page terminal, but I'd like output to always be dumped to stdout

我对 Windows 命令提示符下 git 命令的以下行为有点困惑。

这显示了与交互式列表 VIM(我认为)相当的结果

git branch -a

结果类似于以下内容,我不知道使用什么组合键来滚动输出(我确实注意到 q 结束了输出)。

但是这显示了一个“正常”的结果,只是将输出转储到标准输出

git show-ref --tags --heads

这是我喜欢的:

如何将所有输出转储到标准输出?

我希望所有命令都以相同的方式工作。 Esp 如果我想在批处理脚本或其他东西中自动执行 git 命令,我不能使用某种交互式 shell.

我注意到此行为似乎是由 TERM=msys 环境变量设置引起的,如果不存在,其行为相同。我不知道是否可以使用其他设置。

最后,虽然彩色结果可能很有趣,但我可以通过使用 Git BASH 来获得它。但是当我直接从 Windows 命令 运行 命令时,我希望它们都只是将输出回显到标准输出。

我不记得这是以前的行为,所以我猜是我安装了一些东西来解决问题;)。我在这台机器上 Windows 10,git、bash 等是最新的。

这就是 git 所谓的 寻呼机。您可以使用以下命令为特定命令禁用它:

git --no-pager branch -a

(注意 --no-pager 位于 git 和子命令之间,因为它是一个全局开关)。

如果你想配置你的系统,这样你就不必记住了,来自 man git-config:

pager.<cmd>

If the value is boolean, turns on or off pagination of the output of a particular Git subcommand when writing to a tty. Otherwise, turns on pagination for the subcommand using the pager specified by the value of pager.<cmd>. If --paginate or --no-pager is specified on the command line, it takes precedence over this option. To disable pagination for all commands, set core.pager or GIT_PAGER to cat.

也就是说,例如,您可以仅使用 git config --global pager.branch false 禁用 git-branch 的寻呼机。

如果您想为所有命令禁用它,请执行 git config --global core.pager cat。或者你可以尝试设置环境变量GIT_PAGER=cat,当然