Why do I have to hit 'Q' at the end of 'git log'?

后端 未结 7 718
挽巷
挽巷 2020-12-12 14:00

Consider:

git log -n 20 --pretty=oneline

I am telling Git that I need to see only the last 20 commits. I hate to hit Q to get ri

相关标签:
7条回答
  • 2020-12-12 14:37

    The q is used to close the command line program used to view the logs...

    You can use another log viewer, like gitk:

    gitk -n 20
    
    0 讨论(0)
  • 2020-12-12 14:39

    Git is automatically paging the output for you, since logs tend to easily overflow a single terminal window size (you're in one of the rare exceptions - a oneline format and a small commit limit). If you don't want this, use:

    git --no-pager log -n 20 --pretty=oneline
    

    Note that this does mean you'll get some ugly wrapping, because the pager was previously turning off wrapping for you (since you could use the cursor keys to scroll left-right).

    0 讨论(0)
  • 2020-12-12 14:40

    You can "turn off" git paging by telling it to use cat instead of less. Thereafter, pipe the output through less when you do want paging, or head if you just want to see the top, etc.

    git config --global core.pager cat
    

    I turn off automatic paging because I often run git from within emacs, which neither needs nor plays well with less.

    0 讨论(0)
  • 2020-12-12 14:43

    Alias for a log command where you don't have to click q to to make it go away:

    git config --global alias.hist '!git --no-pager log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short --max-count=10'
    
    0 讨论(0)
  • 2020-12-12 14:51

    less accepts -F argument to quit automatically if content fits on one screen

    0 讨论(0)
  • 2020-12-12 14:52

    git log -n 20 --pretty=oneline | cat

    is a little shorter that the --no-pager option but will also remove any colours present.

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