如何让 git diff 写入标准输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17077973/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:22:23  来源:igfitidea点击:

How to make git diff write to stdout?

gitterminal

提问by nacho4d

By default git diffprints all +-lines to the stdout however I have a (devian) machine (which I connect through ssh) where git diffleads me to an editor (which I don't know which is) and I need to press qto continue.

默认情况下,将git diff所有+-行打印到标准输出,但是我有一台(devian)机器(我通过 ssh 连接),git diff它将我带到一个编辑器(我不知道是哪个),我需要按q才能继续。

I've checker git config and it looks like :

我检查了 git config,它看起来像:

$ git config --list
user.name=XXX
user.email=XXX@XXX
color.ui=false
difftool.prompt=false
mergetool.prompt=false
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=XXX
branch.master.remote=origin
branch.master.merge=refs/heads/master
$ git config --global --list
user.name=XXX
user.email=XXX@XXX
color.ui=false
difftool.prompt=false
mergetool.prompt=false
$ git config --system --list
'/etc/gitconfig': No such file or directory

Is there a place I am missing? Maybe the unknown tool is a fallback or something because I my machine is missing something? Any help is appreciated. Thanks.

有没有我想念的地方?也许未知工具是后备工具或其他什么东西,因为我的机器缺少某些东西?任何帮助表示赞赏。谢谢。

回答by mipadi

By default, Git sends its diff output (and generally any output that may be more than a screenful) to the system's pager, which is a utility that prints only one screenful of output at a time. If you want to disable the pager when you run a command, pass --no-pagerto Git:

默认情况下,Git 将其 diff 输出(以及通常可能超过一屏的任何输出)发送到系统的pager,这是一个一次仅打印一屏输出的实用程序。如果您想在运行命令时禁用寻呼机,请传递--no-pager给 Git:

$ git --no-pager <subcommand> <options>

This can be run for any Git command.

这可以针对任何 Git 命令运行。

If you want to disable it by default for diff only, you can set the diff pager to catby running:

如果您想在默认情况下仅对 diff禁用它,您可以cat通过运行将 diff 寻呼机设置为:

$ git config pager.diff false

If you want to disable it by default for all commands, you can set the Git pager to catby running:

如果要默认为所有命令禁用它,可以cat通过运行将 Git 寻呼机设置为:

$ git config --global core.pager cat

回答by friederbluemle

The following core.pagervalue uses less, which prints to stdout, and also has pager functionality (if required), enabling scrolling up and down (unlike cat):

以下core.pager值使用less,它打印到标准输出,并且还具有寻呼功能(如果需要),可以上下滚动(与 不同cat):

$ git config --global core.pager "less -FRSX"

It immediately quits if the diff fits on the first screen (-F), outputs raw control characters (-R), chops long lines rather than wrapping (-S), and does not use termcap init/deinit strings (-X).

如果 diff 适合第一个屏幕 ( -F),它会立即退出,输出原始控制字符 ( -R),截取长行而不是换行 ( -S),并且不使用 termcap init/deinit 字符串 ( -X)。

回答by Shasak

You can also simply use catfor any gitcommand if you don't care about the colors.

如果您不关心颜色,您也可以简单地cat用于任何git命令。

So git diff | catfor your case.

所以git diff | cat对于你的情况。

Edit:as pointed out in the comments if you do care about the colors use:

编辑:如评论中指出的那样,如果您确实关心颜色的使用:

git diff --color | cat

git diff --color | cat