仅针对 stash 命令关闭 git 中的寻呼机

发布于 2024-10-03 12:43:34 字数 665 浏览 7 评论 0原文

我通常喜欢在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

耳钉梦 2024-10-10 12:43:34

从 1.7.7.3 开始,git config --global pager.stash false 实现了这一点。

As of 1.7.7.3, git config --global pager.stash false accomplishes this.

寻梦旅人 2024-10-10 12:43:34

它看起来像 stash,任何其他非内置命令(以 shell 脚本形式编写,而不是用 C 语言编写)都会错过寻呼机配置步骤。我向 git 邮件列表发送了一条消息询问此事;看起来这是一个已知问题,但修复起来并不容易。

您看不到别名效果的主要原因是 git 默默地忽略内置命令的别名;这个想法是你永远不想真正使命令不可访问。为了使别名有机会运行,您需要将其命名为 stash 以外的名称。

但是,我认为简单的别名不允许影响 git 命令运行的环境,其中通常包括传递给 git 本身的选项。如果我使用像你这样的别名:

git config alias.foo --no-pager stash
git foo
fatal: alias 'foo' changes environment variables

如果你想正确地做到这一点,你必须使用 !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:

git config alias.foo --no-pager stash
git foo
fatal: alias 'foo' changes environment variables

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 the list_stash function, and add the --no-pager option to its call to git log, or to cover the whole script, set GIT_PAGER=cat at the top.

打小就很酷 2024-10-10 12:43:34

或者,您可以配置 less 在输出少于一个屏幕的情况下退出:

export LESS='-F'

或者,详细地说:

export LESS='--quit-if-one-screen'

如果您的 git 输出中有颜色,您可能还想传递 - r 标志:

export LESS='-F -r'

Alternatively you can configure less to exit if there's less than one screen's worth of output:

export LESS='-F'

Or, verbosely:

export LESS='--quit-if-one-screen'

If you have colours in your git output, you'll probably also want to pass the -r flag:

export LESS='-F -r'
掩饰不了的爱 2024-10-10 12:43:34
stll = "!git --no-pager stash list"

是你的朋友。

stll = "!git --no-pager stash list"

is your friend.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文