How to exit git log or git diff? [duplicate]

2019-01-29 15:10发布

问题:

This question already has an answer here:

  • How to exit a git status list in terminal? 11 answers

I'm trying to learn Git with the help of Git Immersion. There's one thing that frustrates me whenever I use git log or git diff:

I can't figure out what to do next when I encounter this (END) word. I can't type any commands and I end up closing the current bash and open another. How do I type in the next command that I want to use?

回答1:

You're in the less program, which makes the output of git log scrollable.

Type q to exit this screen. Type h to get help.

If you don't want to read the output in a pager and want it to be just printed to the terminal define the environment variable GIT_PAGER to cat or set core.pager to cat (execute git config --global core.pager cat).



回答2:

You can press q to exit.

git hist is using a pager tool so you can scroll up and down the results before returning to the console.



回答3:

The END comes from the pager used to display the log (your are at that moment still inside it). Type q to exit it.



回答4:

Add following alias in the .bashrc file

git --no-pager log --oneline -n 10
  • --no-pager will encounter the (END) word
  • -n 10 will show only the last 10 commits
  • --oneline will show the commit message, ignore the author, date information


回答5:

Actually, there are three ways to do it, precisely.

Type any of the following 3 commands.

  1. :q
  2. :z
    or
  3. Ctrl + z.

P.S.: Sometimes, for someone, one of these options doesn't seem to work and for others it works.



回答6:

I wanted to give some kudos to the comment that mentioned CTRL + Z as an option. At the end of the day, it's going to depend on what system that you have Git installed on and what program is configured to open text files (e.g. less vs. vim). CTRL + Z works for vim on Windows.

If you're using Git in a Windows environment, there are some quirks. Just helps to know what they are. (i.e. Notepad vs. Nano, etc.).



回答7:

In this case, as snarly suggested, typing q is the intended way to quit git log (as with most other pagers or applications that use pagers).

However normally, if you just want to abort a command that is currently executing, you can try ctrl+c (doesn't seem to work for git log, however) or ctrl+z (although in bash, ctrl-z will freeze the currently running foreground process, which can then be thawed as a background process with the bg command).