如何让 git log 不提示继续?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7736781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make git log not prompt to continue?
提问by stijn
I have a couple of git repositories that belong together, and simple batch/bash file to loop over them. I often loop over them with a log command to quickly see what state they are in. This works nicely, except for one thing: if the commit message is longer than the number of characters my console is wide (or has multiple lines), git shows the line, then a newline with (END) and I have to press qto continue (I guess it pipes the output through moreor something like that). Example:
我有几个属于一起的 git 存储库,以及简单的批处理/bash 文件来循环它们。我经常用 log 命令循环它们以快速查看它们处于什么状态。这很好用,除了一件事:如果提交消息比我的控制台宽(或有多行)的字符数长,git显示该行,然后是一个带有 (END) 的换行符,我必须按q才能继续(我猜它会通过more或类似的方式输出输出)。例子:
> gitloop . "git log --decorate=short --pretty=oneline -n1"
18629ae238e9d5832cb3535ec88274173337a501 (HEAD, origin/master, master) short log
625fb891b9b0b8648459b07ace662ae3b7773c7f (HEAD, origin/master, origin/HEAD, master) short log
dc0838118266ba8570ea338c1faddfe8af0387bb (HEAD, origin/work, origin/master, work, master) oops loooooooooooooong log
-(END)
This is rather inconvenient as I have to press qa couple of time, whereas I'd just like to see all those oneliners in one go.
这相当不方便,因为我必须按几次q,而我只想一次性查看所有这些单行。
How can I disable this behaviour (preferrably while still keeping this log format)?
如何禁用此行为(最好同时保留此日志格式)?
回答by toabi
Git has an option to disable the pager:
Git 有一个选项可以禁用寻呼机:
git --no-pager log --decorate=short --pretty=oneline -n1
If your pager cuts lines and you want to retain that behaviour, either pipe to cut
...
如果您的寻呼机切线并且您想保留该行为,则可以通过管道发送到cut
...
git --no-pager log --decorate=short --pretty=oneline -n1 | cut -c 1-$COLUMNS
...or set the environment variable GIT_PAGER
before the invocation:
...或GIT_PAGER
在调用之前设置环境变量:
GIT_PAGER="cut -c 1-${COLUMNS-80}" git --no-pager log --decorate=short --pretty=oneline -n1
回答by vladZamskoi
Another solution for the problem of permanently disabling pagerspecifically when using log
subcommand:
特别是在使用子命令时永久禁用寻呼机问题的另一种解决方案log
:
for current repo only:
git config pager.log false
for your git installation (i. e. all repos on your machine):
git config --global pager.log false
仅适用于当前回购:
git config pager.log false
对于您的 git 安装(即您机器上的所有存储库):
git config --global pager.log false
As you can guess, the same works if pageris needed to be onor offfor some other subcommands selectively.
E. g. for branch
(which prints branches) subcommand it will be
您可以猜到,如果需要选择性地打开或关闭某些其他子命令的寻呼机,则同样有效。
例如 for (打印分支)子命令它将是 branch
git config pager.branch false
git config pager.branch false
Proposed solution is arguably more elegant comparing to
相比之下,提议的解决方案可以说更优雅
using
git --no-pager
each time you run certain command.
Because, quite possible, you don't want to type it each time.specifying
git --no-pager
as an alias forgit
Because, quite possible, you want to avoid implicitglobal config OR you want pagerto be enabled in some cases.rely on some environment variables like
PAGER
orGIT_PAGER
.
Because to do that, you need to ensure they're set in your current terminal session. And, if you want them to be set to some custom value automatically each time your new terminal is created, you need to alter one of shell-bootstrapped files like e. g.~/.bashrc
. It's not a big problem. But these bootstrapped files frequently are altered by other applications as well and contain bunch of other stuff, not just that used by Git. So, in theory, it's better to specify git-related settings usinggit config
rather than put them in e. g.~/.bashrc
.
使用
git --no-pager
每次运行某些命令的时间。
因为,很有可能,您不想每次都输入它。指定
git --no-pager
为别名git
因为,很可能,您希望避免隐式全局配置,或者您希望在某些情况下启用寻呼机。依赖于一些环境变量,如
PAGER
或GIT_PAGER
。
因为要做到这一点,您需要确保在当前的终端会话中设置了它们。而且,如果您希望每次创建新终端时都将它们自动设置为某个自定义值,则需要更改 shell 引导文件之一,例如~/.bashrc
. 这不是什么大问题。但是这些引导文件也经常被其他应用程序更改,并且包含许多其他内容,而不仅仅是 Git 使用的内容。因此,理论上,最好使用git config
而不是将它们放在 eg 中指定与 git 相关的设置~/.bashrc
。
The alternative solution for disabling pager
for all subcommandsis to specify cat
as the utility git will use for paging:
禁用的替代解决方案pager
为所有的子命令是指定cat
为公用事业git会使用分页:
git config core.pager cat
ORgit config --global core.pager cat
git config core.pager cat
或者git config --global core.pager cat
My answer is somewhat rephrasing of the one below:
"prevent git diff from using a pager?"
https://stackoverflow.com/a/6986231/6103242
我的回答是对以下问题的某种改写:
“防止 git diff 使用寻呼机?”
https://stackoverflow.com/a/6986231/6103242
It's referenced to point out another relevant discussion.
引用它是为了指出另一个相关的讨论。
回答by marchozaur
Disable pager for all commands:
禁用所有命令的寻呼机:
git config --global core.pager ''
回答by Nick Constantine
You pipe it to less -F in case --no-pager does not work for you.
如果 --no-pager 对你不起作用,你可以将它传递给 less -F。
git log --decorate --oneline -5 | less -F