How to make git log not prompt to continue?

后端 未结 4 1275
梦毁少年i
梦毁少年i 2020-12-08 01:44

I have a couple of git repositories that belong together, and simple batch/bash file to loop over them. I often loop over them with a log command to quickly see what state t

相关标签:
4条回答
  • 2020-12-08 02:02

    Git has an option to disable the pager:

    git --no-pager log --decorate=short --pretty=oneline -n1
    

    If your pager cuts lines and you want to retain that behaviour, either pipe to cut...

    git --no-pager log --decorate=short --pretty=oneline -n1 | cut -c 1-$COLUMNS
    

    ...or set the environment variable GIT_PAGER before the invocation:

    GIT_PAGER="cut -c 1-${COLUMNS-80}" git --no-pager log --decorate=short --pretty=oneline -n1
    
    0 讨论(0)
  • 2020-12-08 02:03

    Another solution for the problem of permanently disabling pager specifically when using log subcommand:

    • for current repo only:
      git config pager.log false

    • for your git installation (i. e. all repos on your machine):
      git config --global pager.log false

    As you can guess, the same works if pager is needed to be on or off for some other subcommands selectively.
    E. g. for branch (which prints branches) subcommand it will be

    git config pager.branch false


    Proposed solution is arguably more elegant comparing to

    • using git --no-pager each time you run certain command.
      Because, quite possible, you don't want to type it each time.

    • specifying git --no-pager as an alias for git
      Because, quite possible, you want to avoid implicit global config OR you want pager to be enabled in some cases.

    • rely on some environment variables like PAGER or GIT_PAGER.
      Because to do that, you need to ensure they're set in your current terminal session. And, if you want them to be set to some custom value automatically each time your new terminal is created, you need to alter one of shell-bootstrapped files like e. g. ~/.bashrc. It's not a big problem. But these bootstrapped files frequently are altered by other applications as well and contain bunch of other stuff, not just that used by Git. So, in theory, it's better to specify git-related settings using git config rather than put them in e. g. ~/.bashrc.


    The alternative solution for disabling pager for all subcommands is to specify cat as the utility git will use for paging:

    • git config core.pager cat OR
    • git config --global core.pager cat

    My answer is somewhat rephrasing of the one below:
    "prevent git diff from using a pager?"
    https://stackoverflow.com/a/6986231/6103242

    It's referenced to point out another relevant discussion.

    0 讨论(0)
  • 2020-12-08 02:11

    Disable pager for all commands:

    git config --global core.pager '' 
    
    0 讨论(0)
  • 2020-12-08 02:20

    You pipe it to less -F in case --no-pager does not work for you.

    git log --decorate --oneline -5 | less -F
    
    0 讨论(0)
提交回复
热议问题