130

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

I've checker git config and it looks like :

$ 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.

4

4 回答 4

215

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-pager to Git:

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

This can be run for any Git command.

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

$ git config pager.diff false

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

$ git config --global core.pager cat
于 2013-06-13T01:49:10.653 回答
39

The following core.pager value uses less, which prints to stdout, and also has pager functionality (if required), enabling scrolling up and down (unlike 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).

于 2015-07-14T06:50:51.207 回答
32

You can also simply use cat for any git command if you don't care about the colors.

So git diff | cat for your case.

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

git diff --color | cat

于 2016-07-08T16:04:54.657 回答
-1

As @mipadi points out, It's this simple:

git --no-pager diff
于 2022-01-19T00:17:22.880 回答