Prevent git from using pager for short output?

后端 未结 4 651
半阙折子戏
半阙折子戏 2021-01-03 22:11

When I was using Git Bash (Git For Windows) if a command (like git diff) had a short output (I\'m guessing smaller than the terminal\'s height) it would just pr

相关标签:
4条回答
  • 2021-01-03 22:51

    Quick answer: Save the following line to your .bashrc

    export LESS=eFRX
    

    The whys and wherefores are covered in the answers to How do I prevent git diff from using a pager? where the OP is actually looking to remove pagination completely.

    0 讨论(0)
  • 2021-01-03 23:02

    This is not a Git thing, it's a property of your pager. Git doesn't know how long the output is going to be so it will always output using your pager.

    Configure your pager to quit if your output is less than one full screen. With less that's -F. You can set the LESS environment variable with your default switches.

    0 讨论(0)
  • 2021-01-03 23:10

    As of December 2017 if you are using the latest version of less (at least 530) then the below is slightly incorrect. Now -F alone will properly output short output (as if by cat) while not needing -X. Since you can now use -F alone to see short output this means long output will still be properly wiped from the screen once you close less! I highly recommend you update your version of less to get this behavior. It's great!


    Schwern's answer is half correct. For what I was asking it is probably still the correct answer, I was just using the incorrect words. What I wanted wasn't this:

       -F or --quit-if-one-screen
              Causes less to automatically exit if the entire file can be dis‐
              played on the first screen.
    

    That makes nothing appear for short output! If core.pager is less -F and your log is less than one screen, you see nothing.

    What you probably want is less -FX or maybe less -X.

       -X or --no-init
              Disables sending the termcap initialization and deinitialization
              strings  to  the  terminal.   This is sometimes desirable if the
              deinitialization string does something unnecessary, like  clear‐
              ing the screen.
    

    This question over at superuser led me to this.

    Using -FX if the log is less than one screen then it just outputs it (as if by cat).

    Using only -X will still open less if the output is less than one screen but will leave it on the terminal if you quit, if you don't quit right away you can actually use less like normal. Once you try to search though it brings it into "real" less and still does not wipe when done, which is annoying because the windows is now full of ~'s.


    Summary

    • If you don't care what happens with short output, use less
    • If you have an older version of less than 530 and you want short output to be put on the screen as if by cat use less -XF
      • If you have version 530 or newer then just use less -F. See the top of the answer for more info.
    • If you want to perhaps search short output (even though it's less than one screen) then use less -X, but you will have to still press q.
    0 讨论(0)
  • 2021-01-03 23:13

    You could configure git to use cat as the pager (instead of less).

    git config --global core.pager cat
    

    This will add the section

    [core]
        pager = cat
    

    to your ~/.gitconfig file and pipe everything through cat, i.e. just display it.

    It's discussed here How do I prevent git diff from using a pager? in more detail.

    0 讨论(0)
提交回复
热议问题