How to Get Out of Git Log: A Quick Guide

When you run the command:

git log

Git opens up the commit history of your repository in a pager called less. This lets you scroll through all commits, see details like author, date, and commit message. But if you’re new to Git, you might wonder:

How do I exit this screen and get back to the command prompt?


Why Does Git Log Open in a Pager?

Git uses a pager (less by default) to handle long output that won’t fit on one screen. This makes browsing commit history easier, letting you scroll up and down.


How to Exit Git Log

To get out of the Git log view and return to your terminal prompt, simply press:

q

The letter q stands for quit. Once pressed, you exit the pager immediately.


Bonus: Navigating Inside Git Log

  • Use the Up and Down arrow keys to scroll line by line.
  • Press Spacebar to scroll down a full page.
  • Press b to scroll back a full page.
  • Press /keyword and hit Enter to search for a keyword in the log.
  • Press n to move to the next search result.

Alternative: View Limited Log Without Pager

If you want to avoid the pager altogether and just see the last few commits printed directly in the terminal, use:

git log --oneline -n 5

This shows the last 5 commits in a concise one-line format without opening the pager.


Summary

  • Press q to quit the git log pager.
  • Use arrow keys, space, and search for navigation inside the log.
  • Use options like --oneline to get simpler output without paging.

Mastering this little trick saves time and frustration while exploring your project history.

Sharing Is Caring:

Leave a Comment