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?
You can reapply stashed changes with the commands git stash apply and git stash pop . Both commands reapply the changes stashed in the latest stash (that is, stash@{0} ). A stash reapplies the changes while pop removes the changes from the stash and reapplies them to the working copy.
If you no longer need a particular stash, you can delete it with: $ git stash drop <stash_id> . Or you can delete all of your stashes from the repo with: $ git stash clear .
answered Jul 18, 2019 by debashis borgohain (27.5k points) --no-pager to git will tell it to not use a pager. Passing the option -F to less will tell it to not page if the output fits in a single screen. Usage: git --no-pager diff.
The git stash drop command is used to delete a stash from the queue.
As of 1.7.7.3, git config --global pager.stash false
accomplishes this.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With