How to make git diff write to stdout?

后端 未结 3 1983
既然无缘
既然无缘 2021-01-29 20:48

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

相关标签:
3条回答
  • 2021-01-29 21:27

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

    0 讨论(0)
  • 2021-01-29 21:36

    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

    0 讨论(0)
  • 2021-01-29 21:42

    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
    
    0 讨论(0)
提交回复
热议问题