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
jandk, scroll down and up. - The space bar scrolls down one full page.
bscrolls back a full page.qquits.
| Command | Description | Key Press |
git log | View commit history | Press q to exit. |
git diff | View changes made | Press q to exit. |
less | Common pager for output | q - quit j/k - scroll down/up space - page down b - page up |
more | Another pager option | q - quit space - page down |
Skipping the pager
To print the output straight to the terminal, use --no-pager:
Or redirect it to a file to review later in a text editor:
Changing Git's pager
Set a different pager:
Or keep less with different options:
-Fexits automatically if the output fits on one screen.-Xkeeps 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.
Related reading
- How to export revision history from mercurial or git to cvs?
- How to fast-forward a branch to head
- How to find a commit by its hash?
- How to find a deleted file in the project commit history?
- How to find a Github file 's SHA blob
- How to find origin of a branch in git?
- How to find the Git commit that introduced a string in any branch?
- How to find the nearest parent of a Git branch
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.