如何防止“git diff"使用寻呼机? [英] How do I prevent 'git diff' from using a pager?
问题描述
是否有命令行开关可以传递给 git diff
和其他默认使用 less
寻呼机的命令?
Is there a command line switch to pass to git diff
and other commands that use the less
pager by default?
我知道我可以通过管道将它传递给 cat,但这会删除所有语法突出显示.
I know I can pipe it to cat, but that removes all the syntax highlighting.
我知道我可以通过 GITPAGER=cat
(或类似的东西)将全局 .gitconfig 中的寻呼机设置为 cat;但有时我想使用寻呼机(取决于差异的大小).
I know I can set the pager in the global .gitconfig to cat by GITPAGER=cat
(or something like that); but I want to have pager sometimes (depending on the size of the diff).
但是,如果有的话,我更喜欢命令行开关;我无法找到,翻阅手册页.
But, I would prefer a command line switch if there is one; and I am not able to find one, going through the man pages.
推荐答案
--no-pager
到 Git 会告诉它不要使用寻呼机.将选项 -F
传递给 less
将告诉它如果输出适合单个屏幕则不分页.
--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.
用法:
git --no-pager diff
评论中的其他选项包括:
Other options from the comments include:
# Set an evaporating environment variable to use 'cat' for your pager
GIT_PAGER=cat git diff
# Tells 'less' not to paginate if less than a page
export LESS="-F -X $LESS"
# ...then Git as usual
git diff
这篇关于如何防止“git diff"使用寻呼机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!