git-branch command behaves like less

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

When I use the git branch command to list all branches, what I see is the output of git branch | less

The command git branch is supposed to show a list of branches, like ls does for files.

This is the output I get:

How I get the default behaviour of git branch? What causes the paged output?

I am using ZSH with oh_my_zsh (nothing for git in there) and my .gitconfig looks like this.

[user]   email = myemail@mail.com   name = Dennis Haegler [push]   default = simple [merge]    tool = vimdiff [core]   editor = nvim   excludesfile = /Users/dennish/.gitignore_global [color]   ui = true [alias]   br = branch   ci = commit -v   cam = commit -am   co = checkout   df = diff   st = status   sa = stash   mt = mergetool   cp = cherry-pick   pl = pull --rebase [difftool "sourcetree"]   cmd = opendiff \"$LOCAL\" \"$REMOTE\" [mergetool "sourcetree"]   cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh    \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"   trustExitCode = true

回答1:

As mentioned above, this was a default behavior change introduced in git 2.16. You can turn paged output for git branch back off by default with: git config --global pager.branch false



回答2:

Not to argue semantics, but the behavior you're getting is the default. That's why you get it when you don't ask for something different. By default, branch (and numerous other git commands) use a pager when sending output to the terminal.

You can override this default by using the --no-pager option

git --no-pager branch

Or if you redirect the output to a file, git should detect that it isn't writing to a terminal and so should not use a pager anyway. (On the other hand, that suggests a scripting use case, in which case you should consider using a plumbing command like git for-each-ref in preference to git branch.)



回答3:

https://git-scm.com/book/gr/v2/Git-Internals-Environment-Variables

GIT_PAGER controls the program used to display multi-page output on the command line. If this is unset, PAGER will be used as a fallback.

To solve your issue, you could unset PAGER and GIT_PAGER in your shell.



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