6. History

Browsing history

As I mentioned earlier, the git log command is your go-to tool for exploring commit history. Let's run it again to see what it does.

Task

Run the git log command to see the commit history.

Tip: Some Git commands, such as git log, may put your terminal into pager mode, which is designed for browsing long lists. In this mode, you can scroll through the output using the and arrow keys on your keyboard. To exit pager mode, press q.

Great! You should have seen a list similar to this one:

Result:
commit 11a3f60fe6520fb6f83306d94765ac54f8964be0
Author: Your Name <you@example.com>
Date:   2024-03-15
 
Linked styles to hello.html
 
commit 7d5aa020c9b3cf2cb5a21575a33396f36e783cd4
Author: Your Name <you@example.com>
Date:   2024-03-15
 
Added CSS styles
 
commit 346ca091076783c70623aba03fb7139d3d27134f
Author: Your Name <you@example.com>
Date:   2024-03-15
 
Added H1, HTML, and BODY tags to hello.html
 
commit 571a4dd16430d5cc89cd2d509bdfbf097d3db63a
Author: Your Name <you@example.com>
Date:   2024-03-15
 
Initial commit

The problem with the default git log output is that it's quite verbose. Each commit takes up multiple lines, which can be overwhelming when dealing with a long history. Fortunately, git log has many options to customize its output.

One of the most useful options is --oneline, which condenses each commit to a single line. Let's try it out.

Run in Terminal:
git log --oneline
Task

Run git log --oneline to see a more compact commit history.

You should have seen a much more concise output:

Result:
11a3f60 Linked styles to hello.html
7d5aa02 Added CSS styles
346ca09 Added H1, HTML, and BODY tags to hello.html
571a4dd Initial commit

Much better, isn't it? With --oneline, you can quickly scan through the history and find the commit you're looking for.

Nice to know!

The git log command has many other useful options. Here are a few examples:

Run in Terminal:
git log --oneline --max-count=2
git log --oneline --since="5 minutes ago"
git log --oneline --until="5 minutes ago"
git log --oneline --author="Your Name"
git log --oneline --all
Task

Try out some of these git log variations and observe the differences in output.

As you can see, git log is a powerful tool for filtering and formatting commit history. You can combine multiple options to create even more specific queries.

For example, let's try a more advanced git log command:

Run in Terminal:
git log --pretty=format:"%h %ad | %s%d [%an]" --date=short
Task

Run the above git log command and try to decipher its output.

That should look like this:

Result:

11a3f60 2024-03-15 | Linked styles to hello.html (HEAD -> main) [Your Name] 7d5aa02 2024-03-15 | Added CSS styles [Your Name] 346ca09 2024-03-15 | Added H1, HTML, and BODY tags to hello.html (tag: 1.0) [Your Name] 571a4dd 2024-03-15 | Initial commit [Your Name]

Here's what each part of this command does:

  • --pretty="..." defines the output format.
  • %h is the abbreviated hash of the commit.
  • %ad is the commit date.
  • | is just a visual separator.
  • %s is the commit message.
  • %d represents commit decorations (e.g. branch heads or tags).
  • %an is the name of the author.
  • --date=short keeps the date format short.
Great!

If you find yourself using this format often, you can set it as the default. Let's do it for this repository. By the way, if you want to keep this format for all your repositories, add the --global option to the commands below.

Run in Terminal:
git config format.pretty "%h %ad | %s%d [%an]"
git config log.date short
Task

Set the custom log format as the default using the commands above.

Note: that this will only affect the current repository. If you want to set it globally, add the --global option after each git config.

Great! You've now learned how to efficiently browse commit history using git log. This will come in handy as your project grows, and you need to find specific commits.

Let's move on to comparing commits.

Next step
© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

This page is a part of the interactive course about Git version control.

It's a one-of-a-kind course that is integrated into the VS Code code editor. Learning directly in VS Code lets you operate Git exactly as you would in real life, doing real jobs, writing real code.

In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code