仅针对 stash 命令关闭 git 中的寻呼机
我通常喜欢在 git 中使用分页器,但是对于 git stash 来说,分页器让我很烦恼。当调用 git stash list 时,我不想在寻呼机中显示三行输出 - 它迫使我按 q 只是为了使输出不可用再次输入后续的 git stash pop 命令时。
一种解决方案是使用
git --no-pager stash list
,但打字太多(我很懒)。按照 git config
的手册页,我尝试了
git config --global pager.stash false
但是这个似乎并没有按照文档所述进行(实际上,我没有注意到任何效果)。然后我又尝试了
git config --global alias.stash "--no-pager stash"
一下,没有任何明显的效果。
配置得到正确更新,例如
git config pager.stash
false
它只是没有任何效果。我缺少什么?我怎样才能实现 git stash 不使用寻呼机?
I generally like the use of the pager in git, but for git stash
the pager annoys me. When calling git stash list
, I don't want to be shown the three lines of output in the pager -- it forces me to press q
just to make the output unavailable again when typing the folow-up git stash pop
command.
One solution would be to use
git --no-pager stash list
but that's to much typing (I'm lazy). Following the man page of git config
, I tried
git config --global pager.stash false
but this doesn't seem to do what the documentation says (actually, I didn't notice any effect). Then I tried
git config --global alias.stash "--no-pager stash"
again without any noticable effect.
The configuration gets properly updated, for example
git config pager.stash
false
It just does not have any effect. What am I missing? And how can I achieve that git stash
does not use the pager?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从 1.7.7.3 开始,
git config --global pager.stash false
实现了这一点。As of 1.7.7.3,
git config --global pager.stash false
accomplishes this.它看起来像 stash,任何其他非内置命令(以 shell 脚本形式编写,而不是用 C 语言编写)都会错过寻呼机配置步骤。我向 git 邮件列表发送了一条消息询问此事;看起来这是一个已知问题,但修复起来并不容易。
您看不到别名效果的主要原因是 git 默默地忽略内置命令的别名;这个想法是你永远不想真正使命令不可访问。为了使别名有机会运行,您需要将其命名为
stash
以外的名称。但是,我认为简单的别名不允许影响 git 命令运行的环境,其中通常包括传递给 git 本身的选项。如果我使用像你这样的别名:
如果你想正确地做到这一点,你必须使用
!git --no-pager stash
,这样它就会生成一个子 shell 并重新调用 git。另一个临时修复方法是直接编辑 libexec/git-core/git-stash ,因为它是 shell 脚本。只需找到
list_stash
函数,并将--no-pager
选项添加到其对git log
的调用中,或者覆盖整个脚本,在顶部设置GIT_PAGER=cat
。It looks like stash, and any other non-builtin command (written as a shell script, rather than in C) misses out on the pager config step. I sent a note to the git mailing list asking about this; it looks like it's a known issue, but not totally trivial to fix.
The primary reason you're seeing no effect from your alias is that git silently ignores aliases for built-in commands; the idea is that you never want to actually make a command inaccessible. For the alias to have a chance of being run, you need to name it something other than
stash
.However, I believe that simple aliases are not permitted to affect the environment a git command is run in, which generally includes the options passed to
git
itself. If I use an alias like yours:If you want to do that properly, you'd have to use
!git --no-pager stash
, so that it'll spawn a subshell and reinvoke git.Another temporary fix, since it's a shell script, would be to go edit
libexec/git-core/git-stash
directly. Just go find thelist_stash
function, and add the--no-pager
option to its call togit log
, or to cover the whole script, setGIT_PAGER=cat
at the top.或者,您可以配置
less
在输出少于一个屏幕的情况下退出:或者,详细地说:
如果您的 git 输出中有颜色,您可能还想传递
- r
标志:Alternatively you can configure
less
to exit if there's less than one screen's worth of output:Or, verbosely:
If you have colours in your git output, you'll probably also want to pass the
-r
flag:是你的朋友。
is your friend.