32

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?

5
  • Do you have any other pager-related config? Stash doesn't use the pager for me.
    – Cascabel
    Nov 19, 2010 at 14:46
  • Strike that: the list subcommand does indeed paginate, and ignores the config.
    – Cascabel
    Nov 19, 2010 at 14:58
  • 2
    See my answer below: git config --global pager.stash false not working was a bug fixed in git 1.7.7.3 and later.
    – cbowns
    Feb 3, 2012 at 1:30
  • 1
    @sven-marnach could you change the right answer to cbowns's one?
    – radistao
    Oct 24, 2016 at 10:16
  • Another motivation for same goal: I religiously run git stash show -v before git stash drop, and I want the diff to remain in terminal (in case I did a mistake, or just for reference — frequently I do want to redo a small part of the changes in a different way). Nov 13, 2017 at 11:45

4 Answers 4

50

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

11

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.

5
  • Thanks for the info and for bringing this up on the git mailing list (I also read the answer to your mail there). Regarding the alias: I also tried a different name than stash, but the effect was the same. Strangely, I did not get an error message (version 1.7.2.3), so I figured the name wasn't the reason. I will just patch the script for now. Nov 19, 2010 at 17:05
  • 1
    @Sven: Do you actually have more than one screen's worth of stashes to list? Or is your pager not quitting after less than one screen of output?
    – Cascabel
    Nov 19, 2010 at 17:19
  • @Sven: And I'm not sure why you don't get that error. That check was added a long, long time ago (v1.5.3). The subshell alias (!...) should work fine though too, though, and avoid having to edit git itself.
    – Cascabel
    Nov 19, 2010 at 17:34
  • 2
    As I wrote in my original post, I usually have just a few stashes, and certainly never more than one page :). My pager (less of course) is not exiting anyway. I figured out this is because I set the LESS environment variable in my .bashrc, so git does not overwrite it with FRSX. I updated my .gitconfig to include -FX in the options to less manually, and now everything works fine. Nov 19, 2010 at 18:50
  • @Sven: Aha! I was wondering if you had a nonstandard pager or something. Glad you found a way!
    – Cascabel
    Nov 19, 2010 at 22:40
7

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'
4
  • This solution is already buried in the comments to Jefromi's answer (somehow). It is good to have it in an answer of its own, though. Mar 26, 2012 at 11:25
  • 3
    Doesn't work here (xterm on pts) because after less quit, there is nothing left of less display, it redraws the previous prompts. But it works on the term "linux" on tty1.
    – lolesque
    Apr 18, 2012 at 15:46
  • Yeah, on some systems/terminals output disappears because it all goes to "alternate screen" and is immediately switched back :-( Adding --no-init might help. Nov 13, 2017 at 11:37
  • 1
    you can also do git config --global core.pager 'less --quit-if-one-screen' if you prefer to affect only git and not other | less uses. Nov 13, 2017 at 11:38
0
stll = "!git --no-pager stash list"

is your friend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.