Git
Git Log
Git Diff
Version Control
Command Line

How to exit git log or git diff

Codemia Knowledge Hub ·

Press q. Git shows the output of git log and git diff in a pager, usually less on Unix-like systems, and q quits it. The same key works in more.

Why Git opens a pager

Git sends the output of commands that produce more text than fits in the terminal window to a pager. The pager is usually less, though you can configure it. It lets you scroll through long output, such as a large project's history or a big diff, instead of having everything scroll off the screen before you can read it.

That is also why the command does not return to the prompt on its own. People new to the command line are often not familiar with how pagers work, and many assume ctrl-c will close the output, but that is not how you exit a pager.

Moving around in the pager

  • Arrow keys, or j and k, scroll down and up.
  • The space bar scrolls down one full page.
  • b scrolls back a full page.
  • q quits.
CommandDescriptionKey Press
git logView commit historyPress q to exit.
git diffView changes madePress q to exit.
lessCommon pager for outputq - quit j/k - scroll down/up space - page down b - page up
moreAnother pager optionq - quit space - page down

Skipping the pager

To print the output straight to the terminal, use --no-pager:

bash
  git --no-pager log
  git --no-pager diff

Or redirect it to a file to review later in a text editor:

bash
  git log > log.txt
  git diff > diff.txt

Changing Git's pager

Set a different pager:

bash
  git config --global core.pager 'more'

Or keep less with different options:

bash
  git config --global core.pager 'less -F -X'
  • -F exits automatically if the output fits on one screen.
  • -X keeps the content in the terminal after you quit instead of clearing the screen.

Other pagers have their own keys. more usually supports q to quit and space to move down, but cannot move back. most is more feature-rich and usually supports keys similar to less.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 11,000 interview practice questions for 300+ companies, searchable by company and role.

Browse interview questions