The Mijingo Blog

Latest news, updates, free tutorials, and more from Mijingo.

Understanding Git Log

by Ryan Irelan

Git logs allow you to review and read a history of everything that happens to a repository. The history is built using git-log, a simple tool with a ton of options for displaying commit history.

What’s in Log?

A Git log is a running record of commits. A full log has the following pieces:

  • A commit hash (SHA1 40 character checksum of the commits contents). Because it is generated based on the commit contents it is unique.
  • Commit Author metadata: The name and email address of the author of the commit.
  • Commit Date metadata: A date timestamp for the time of the commit
  • Commit title/message: The overview of the commit as written in the commit message.

A Typical Log

Git logs can be whatever you want them to be. Git-log offers dozens and dozens of options but let’s start with the simplest.

git log 

This outputs the most basic log:

commit 98aa8d722bdecc4e56156cfe1a793a4d16848eb8
Author: Ryan Irelan 
Date:   Sat Jan 10 23:26:40 2015 -0600
Adding in new homepage
Includes the assets needed for Foundation
commit dd8d6f587fa24327d5f5afd6fa8c3e604189c8d4
Author: Ryan Irelan 
Date:   Tue Jan 6 20:07:17 2015 -0600
added origination declaration at bottom of RSS feed

This is a snippet of the log, showing two commits. We have a commit SHA1 hash, the author, the date, and the commit message, explaining what happened in the commit. This layout is the default look of the log.

Git has something called Commit Limiting to make it easier to narrow down hundreds or thousands of commits to the ones you want to review.

Directory Restricted Log

The default log is great for grabbing a quick look at what just happened in the repository. But it takes up a lot space and you can only see a handful of commits at once.

When I’m developing a project, I sometimes only want to know what happened in a specific directory. Let’s say I’m working on some CSS or Sass and only want to know about changes in my Sass directory. I can get much more specific with git-log and restrict it only to a specific directory.

git log scss

This will only return commits that had changes in the scss directory.

Log by branch

We can use a similar syntax as directory restriction and build a log for just one branch. We only need to specify the branch we want to see.

git log develop

We can clean that up a little by removing any merge commits (which can bulk up the log if there are a lot of merges, like there would be a develop branch.

git log develop --no-merges

Learning More About Git-Log

To learn more about Git-log, like time-restricted logs, search logs, and more, check out our Intermediate Git course that will make you a Git power user.

Learn more about Git

Filed Under: Git