How to exit git log or git diff [duplicate]
Asked Answered
A

7

1306

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 log shows (END) marker

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 window and open another. How do I type in the next command that I want to use?

Anecdote answered 28/2, 2012 at 14:30 Comment(7)
Even after I use q+Enter to quit, the <END> reappears every time I begin typing again. It eats up my first character. Thereafter, I'm able to type the command I want. However, I'd rather not have this behavior at all. I'm on Windows. Suggestions?Frankfrankalmoign
Windows users: you must type q+enter first. Once you escape with cntl+c, you'll be stuck in that weird loop. Use ONLY q+enter to exit.Adis
It's possible to break out by repeatedly typing q+enter+q+enter+q+enter until the end of time no matter what the console shows.Presumptuous
I fixed it by using another console, typing "ps" to find all the processes, then typing "kill -9 <PID for the less command>" to kill less. Nothing else worked.Spaniard
just press ( :qa ) without parentheses and hit Enter, it will exit.Ardeen
@KodiakMx brought me here too but its seven years after ptkvsk and 43 other users agreed with himEcbolic
Usually you just curse and then close the window, the answers below provide better options thoughAdcock
L
1989

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).

Luxe answered 28/2, 2012 at 14:30 Comment(15)
I kept on pressing q: as one would do to get out of vi! Thanks!Ollie
@Affan: To quit vi use :q. q: opens a command window which can be exited with :q (but this won't quit vi then).Desist
Simplest way to avoid the pager just once: "git log | cat". I also like to do "git log > /tmp/foo" and then view /tmp/foo in the editor of my choice. For some reason, that works better for me.Calyptra
q was the first thing I tried because some other git command needs it to exit; it definitely does not work for git log.Mobocracy
q: was what I needed in Win 7. Just Q leads to bizarre behavior where it keeps bouncing back between command prompt and this vi or pseudo-win-vi thing.Zolner
Nothing appeared to work in posh-git. So I just exited. Ugh.Sello
I have core.pager = cat in my .gitconfig, so git commands just print their output unless I explicitly pipe it through less.Quizzical
pressing q works like a charm :)Jadajadd
q exits, but returns a non-zero value. less returns zero when exiting with q.Silage
Good golly I should not have to read all the answers and comments to find the solution for WINDOWS q: is only thing that worked per @ErikReppen comment. I'm on Windows 10Estremadura
If you need git log to return a value, for use in a script, you can flag --no-pager. So it'd be git --no-pager log -1 --pretty='%B'Modulus
this is so counter-intuitive, because we usually do ctrl + c to closeBudding
just press ( :qa ) without parentheses and hit Enter, it will exit.Ardeen
By Hitting the Q worked :)Tennies
Wow knowing the existence of this less component, and its name, helped me a lot! Thanks!Tummy
R
152

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.

Romain answered 31/8, 2015 at 20:35 Comment(3)
I just had to press q since there is already ":" added in the Git bash.Predacious
Are these vim commands?Kevenkeverian
in zsh on macOS control+Z will suspend the process, not terminate. Pressing q however works fine.Tropo
W
55

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
Wiliness answered 4/1, 2016 at 8:41 Comment(2)
git --no-pager is a thing I was looking for, thanks!Chemoreceptor
You can also do GIT_PAGER=cat git diff to use cat temporarily, or, alternatively to this, save it in your shell environment.Giraldo
H
50

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.

Halyard answered 28/2, 2012 at 14:35 Comment(0)
D
36

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

Desist answered 28/2, 2012 at 14:33 Comment(0)
J
11

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.).

Jospeh answered 17/11, 2015 at 19:50 Comment(2)
I wouldn't have considered using a graphical program such as Notepad with one like Git that runs in a terminal.Acetone
Ctrl-Z on Unix-like platforms leaves the process present but stopped; this only makes sense on Windows (to the extent that anything at all makes sense on Windows).Technicality
P
8

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).

Prytaneum answered 8/3, 2016 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.