Skip to content

Git Log


What Will We Learn?
  • Viewing git commit history.
  • Common patterns of viewing history
  • Applying custom filters
  • git shortlog to see who contributed the most in the project

What is git log For?

git log basically helps you to view your commit history. At it basics it shows enough information for you to know anything about the particular commit which includes:

  • Commit hash (SHA-1 identifier)
  • Author information (Who is committer?)
  • Timestamp (When was the change committed?)
  • Commit message (What was commit for?)

A sample example can be:

commit 3c0c5c8a315534b03bcc7134399b84d9441c8e09 (HEAD -> master, origin/master)
Author: Joe Avilez <[email protected]>
Date:   Mon Jul 13 23:35:27 2026 +0530

    content: add Committing Changes

commit bd0723bee6829dc1a487030f6305d5ccb87af7dc
Author: Joe Avilez <[email protected]>
Date:   Mon Jul 13 14:46:15 2026 +0530

    content: add How to use `git status`

Tip

By default, git log shows all commit. You can pipe it to less to view page by page as git log | less or git log | cat to see in full.

Filtering and Customizing Output

You don’t always want to view full commit log. So apply filtering.

One Line Output

git log --oneline

View by Author

Git auto applies global filter *. So, it shows all the commit by the author matching “Joe” prefix.

git log --author="Joe"

Graph View

Graph view can be important particularly when working with multiple branches.

git log --graph --decorate

Tip

Using --oneline with --graph is common pattern.

Exploring Changes

By using -p or --patch option, Git can tell you what changes i.e. diffs for each commit.

git log --patch

Commit Affecting Specific File

Sometimes you wanna see commits that introduces changes to particular file. You can see that with -- <file> pattern. For example to see commits that records app.py file, you can:

git log -- app.py

Commit by Message

Search commits affecting a file by message:

git log --grep="fix" -- app.py

Search commits by commit message:

git log --grep="feat"

Find When a String Was Added

Ever wondered when a specific word or text first appeared in your project? Git can help.

git log -S "markup"

Tip

If you want to match by regex pattern, you can use -G option.

This shows the commits where "markup" was added or removed, making it easy to find when that piece of text entered your codebase.

Filter by Date

git log --since="2 hours ago"
git log --since="1 month ago"

This table will help you filtering by date.

FilterCommandDescription
Last hourgit log --since="1 hour ago"Commits from the last hour
Todaygit log --since="midnight"Commits since today’s midnight
Yesterdaygit log --since="yesterday"Commits since yesterday
Last weekgit log --since="1 week ago"Commits from the last week
Last monthgit log --since="1 month ago"Commits from the last month

Customizing with pretty

For your own style of output, you can use --pretty option.

Here are the Common git log --pretty Formats:

FormatCommandOutput
One linegit log --pretty=oneline<hash> <message>
Shortgit log --pretty=shortAuthor and message
Medium (default)git log --pretty=mediumStandard commit details
Fullgit log --pretty=fullIncludes author and committer
Fullergit log --pretty=fullerFull details with both dates
Referencegit log --pretty=referenceCompact reference format
Emailgit log --pretty=emailEmail patch format
Rawgit log --pretty=rawRaw commit object
Customgit log --pretty=format:"%h %an %ad %s"Custom output

Here are the Common format: Placeholders:

PlaceholderDescription
%hAbbreviated commit hash
%HFull commit hash
%anAuthor name
%aeAuthor email
%adAuthor date
%cdCommitter date
%sCommit subject
%bCommit body
%dRefs (branches/tags)
%cnCommitter name

Top Custom git log --pretty=format: Examples:

PurposeCommand
Hash + messagegit log --pretty=format:"%h %s"
Hash + author + messagegit log --pretty=format:"%h %an %s"
Hash + date + messagegit log --pretty=format:"%h %ad %s" --date=short
Hash + author + date + messagegit log --pretty=format:"%h %an %ad %s" --date=short
Full custom (hash, refs, author, relative date, message)git log --pretty=format:"%C(yellow)%h%Creset %C(cyan)%d%Creset %C(green)%an%Creset %C(blue)%ar%Creset %s"

Git Shortlog: Contributions per Author

Contributors Summary

Basic usage is git shortlog which shows number of commits per author with commit message.

$ git shortlog

Alice Johnson (3):
      Initial project setup
      Add authentication
      Fix login bug

Bob Smith (2):
      Add user profile page
      Improve API documentation

Carol Lee (1):
      Update README

Want to know who has contributed the most to a repository? Use git shortlog:

git shortlog -sn

This prints a summary of contributors sorted by the number of commits.

Show Contributor Names Only

git shortlog -sne

Displays the commit count, contributor name, and email address.

Contributions in the Last Month

git shortlog -sn --since="1 month ago"

Shows who has been most active during the last month.

Contributions by Branch

git shortlog -sn main

Summarizes contributions on the main branch only.

Contributions for a Specific File

git shortlog -sn -- app.py

Shows who has contributed commits that affected app.py.

Last updated on