Turning off the pager in git for the stash command only

喜你入骨 提交于 2019-12-04 22:20:34

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.

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

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'
stll = "!git --no-pager stash list"

is your friend.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!