如何退出 git log 或 git diff
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9483757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exit git log or git diff
提问by Wern Ancheta
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
:
我正在尝试在Git Immersion的帮助下学习 Git 。
每当我使用git log
or时,有一件事让我感到沮丧git diff
:
I can't figure out what to do next when I encounter this (END)
word.
当我遇到这个(END)
词时,我想不出下一步该怎么做。
I can't type any commands, and I end up closing the current Bash window and open another. How do I type in the next command that I want to use?
我无法输入任何命令,我最终关闭了当前的 Bash 窗口并打开了另一个。如何输入我想使用的下一个命令?
回答by Fred Foo
You're in the less
program, which makes the output of git log
scrollable.
你在less
程序中,这使得输出git log
可滚动。
Type qto exit this screen. Type hto get help.
键入q以退出此屏幕。键入h以获取帮助。
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
).
如果您不想在寻呼机中读取输出并希望将其打印到终端,请将环境变量定义GIT_PAGER
为cat
或设置core.pager
为cat
(execute git config --global core.pager cat
)。
回答by seanhodges
You can press qto exit.
您可以按q退出。
git hist
is using a pager tool so you can scroll up and down the results before returning to the console.
git hist
正在使用寻呼机工具,因此您可以在返回控制台之前上下滚动结果。
回答by shrexchauhan
Actually, there are three ways to do it, precisely.
实际上,确切地说,有三种方法可以做到。
Type any of the following 3 commands.
键入以下 3 个命令中的任何一个。
- :q
- :zor
- Ctrl+z
- :q
- :z或
- Ctrl+z
P.S.: Sometimes, for someone, one of these options doesn't seem to work and for others it works.
PS:有时,对于某些人来说,这些选项之一似乎不起作用,而对其他人却起作用。
回答by J4cK
Add following alias in the .bashrc file
在 .bashrc 文件中添加以下别名
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
--no-pager
会遇到(END)词-n 10
将只显示最后 10 次提交--oneline
将显示提交信息,忽略作者、日期信息
回答by Benjamin Bannier
The END
comes from the pager used to display the log (your are at that moment still inside it). Type qto exit it.
在END
来自用来显示日志寻呼机(你是在那一刻还在里面呢)。键入q以退出它。
回答by Jeremy
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.
我想对提到 CTRL + Z 作为选项的评论表示赞赏。归根结底,这将取决于您安装了 Git 的系统以及配置为打开文本文件的程序(例如 less 与 vim)。CTRL + Z 适用于 Windows 上的 vim。
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.).
如果您在 Windows 环境中使用 Git,则有一些怪癖。只是有助于了解它们是什么。(即记事本与 Nano 等)。
回答by HelloGoodbye
In this case, as snarly suggested, typing qis the intended way to quit git log
(as with most other pagers or applications that use pagers).
在这种情况下,正如 snarly 建议的那样,键入q是退出的预期方式git log
(与大多数其他寻呼机或使用寻呼机的应用程序一样)。
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-zwill freeze the currently running foreground process, which can then be thawed as a background process with the bg
command).
但是,通常情况下,如果您只想中止当前正在执行的命令,您可以尝试ctrl+c(但似乎对 不起作用git log
)或ctrl+z(尽管在bash 中,ctrl-z会冻结当前正在运行的前台进程,然后可以将其解冻为带有bg
命令的后台进程)。