Elena' s AI Blog

Git Log

24 Apr 2025 / 11 minutes to read

Elena Daehnhardt


Matrix fell, digital world https://s.mj.run/Z-JpN6R7b6E HD, Midjourney 6.1 April 2025
I am still working on this post, which is mostly complete. Thanks for your visit!


Since I usually work on several projects simultaneously, I often start my day with a Git log to see where I should continue my coding or writing. I think that Git log is one of the most important commands.

Introduction

git log lists all commits, details such as the author’s name, commit date, and descriptive messages explaining what was changed or fixed. This makes it an essential tool for tracking feature launches, debugging issues, and efficiently collaborating within a team.

This post explores various useful options for a git log, enabling you to quickly gain insights into your project’s history. Let’s go!

How to Use Git Log

The git log command displays the entire commit history for the current branch, first showing the most recent commit.

Viewing Basic Commit History

To see a simple commit history, use:

git log

This command lists commit hashes, author details, timestamps, and commit messages. Here’s an example:

commit b2f6f5db7af5921f32b2742f
Author: Jane Doe <jane@example.com>
Date:   Tue Mar 27 14:50:23 2025 -0400

    Fix bug in user authentication

commit a25ac9abcf384f8655327a8a
Author: John Smith <john@example.com>
Date:   Mon Mar 26 09:15:10 2025 -0400

    Add user profile page

commit 98f530da3fae26554f3d28ed
Author: Jane Doe <jane@example.com>
Date:   Sun Mar 25 10:41:50 2025 -0400

    Initial commit

Quick Overview (One-Line Format)

To quickly scan through an extensive commit history, use the one-line option:

git log --oneline

This compact view displays each commit in a single concise line, showing only the shortened commit hash and the commit message:

b2f6f5d Fix bug in user authentication
a25ac9a Add user profile page
98f530d Initial commit

Viewing Changes (Patch Mode)

For detailed insights into what exactly changed with each commit, you can use the patch (-p) option:

git log -p

This reveals the exact additions and deletions each commit introduces, making it invaluable for code reviews and debugging.

Limiting the Number of Commits

If you want to view only the most recent commits, limit the output with the -n flag:

git log -n 5

Replace 5 with the number of commits you’d like to review. This is especially useful when quickly checking recent activity.

Filtering Commits by Author

To see contributions from a specific developer, filter the logs by author:

git log --author="Jane Doe"

This highlights all commits made by the specified author, which is ideal for tracking individual contributions or debugging.

It is very useful, and you don’t have to provide your full name. I just use my first name to see my commits.

Top 10 Most Useful git log Options

The table below lists the top 10 most useful git log options, chosen for their frequent use in development abd debugging.

Option(s) Description Why It’s Useful (Use Case)
--oneline Condenses commit info into a single line (abbreviated hash and title). Often includes --abbrev-commit. Provides a compact, high-level overview of commit history—ideal for quickly scanning changes or filtered results. Great for context before digging deeper.
--graph Displays an ASCII graph showing branch structure alongside commits. Visually clarifies how branches and merges evolved. Frequently paired with --oneline and --decorate for clear and readable output.
-p, --patch Shows full diffs introduced by each commit (line-by-line changes). Crucial for code reviews and debugging—shows exactly what was added or removed. Provides the most granular view of a commit’s impact.
--stat Displays summary stats per commit (files changed, lines added/removed). Gives a quick snapshot of a commit’s scope and affected files without full diffs. Useful for identifying large changes.
-n <number>, --max-count=<number> Limits output to the specified number of most recent commits. -n 1 shows only the latest. Prevents log overload in large repos. Ideal for checking the latest commits or trimming down filtered results.
--author="<pattern>" Filters commits by author name/email using a regex pattern. Case-sensitive. Tracks changes by specific contributors. Useful for reviewing team contributions or auditing your own work.
--since="<date>", --after="<date>", --until="<date>", --before="<date>" Filters commits based on date. Supports formats like YYYY-MM-DD, or 2 weeks ago, yesterday, etc. Helps focus on recent work, bugs from a certain period, or commits for release notes.
--grep="<pattern>" Filters commits whose messages match a given regex. Use -i for case-insensitive search. Perfect for finding commits related to specific features, bug IDs, or keywords like Fixes #123.
-S"<string>" Filters commits that added/removed lines containing a specific string. Excellent for finding when a function, variable, or config line was added or removed—great for debugging history.
-- <path> Limits commit output to changes made to specific file(s) or directory. Use -- to separate options from path. Helps trace the history of a module, config file, or any specific part of your project.

Combining Options

While individual options are useful, the true efficiency of git log is realized when combining filtering and formatting options to create highly specific views of the repository’s history.

A concise history from a particular author

You can combine different options to customize your log output further. For instance, if you want a concise history from a particular author:

git log --oneline --author="John Smith"

Let’s overview several scenarios and useful Git log options.

Reviewing Recent Feature Work by a Specific Author

Let’s image that a developer needs to review all commits contributed by “Linus” within the last two weeks that affected files within the builtin/ directory. A concise, graphical view showing branch context is desired.

git log --author="Linus" --since="2 weeks ago" --oneline --graph --decorate -- builtin/

This command combines multiple options:

–author=”Linus”: Filters commits authored by Linus. –since=”2 weeks ago”: Filters for commits within the specified timeframe. –oneline: Formats each commit concisely onto a single line. –graph: Adds an ASCII graph to visualize branch structure. –decorate: Shows branch and tag names pointing to commits. – builtin/: Restricts the history to changes affecting the builtin/ path.

The result is a highly focused and readable log tailored to the specific review task.

Finding When a Specific Bug Fix Was Introduced

A bug tracked as “Issue-123” was reportedly fixed. The developer needs to find the exact commit and understand the code changes made.

git log --grep="Issue-123" -p -n 1

The option –grep=”Issue-123” filters commits whose messages contain the issue identifier.

-p: Displays the full patch (diff) for the matching commit(s).

-n 1: Limits the output to the single most recent commit matching the grep pattern. This assumes the fix is likely in the latest commit mentioning the issue.

This command directly targets the commit related to the specific issue and shows the precise changes implemented for the fix.

Investigating When a Specific Function Call Was Removed

A developer suspects a function call, userformat_find_requirements, was removed from the codebase recently and needs to identify the commit responsible.

Initial Search Command:

git log -S"userformat_find_requirements" --oneline -n 10

The Initial Search:-S”userformat_find_requirements”: Searches for commits where the number of occurrences of this string changed (indicating addition or removal).

–oneline: Presents potential matches concisely.

-n 10: Limits the search to the last 10 relevant commits for a quick overview.

Follow-up Command (after identifying hash abc1234):

git log -p -n 1 abc1234

Once a likely commit hash (abc1234) is identified from the initial search, this command uses -p to show the detailed patch for that specific commit, confirming the removal and showing the context. This demonstrates the iterative workflow: broad search with -S and –oneline, followed by detailed inspection with -p.

Other Notable Options

–decorate: While often used implicitly or with –oneline –graph, explicitly using –decorate adds branch and tag names to commit output, providing crucial context about the commit’s place in the repository structure.

–follow: This specialized option is invaluable when tracking the history of a single file that has been renamed over time. Standard path filtering stops at the rename, but –follow attempts to trace the history back further.

–no-merges: Useful for simplifying logs, especially on integration branches (like main or develop), by hiding merge commits and focusing only on the commits that introduced substantive changes.

Revision Ranges: Using notations like .. (commits reachable from commit2 but not commit1) or ... (commits reachable from either, but not both) allows for powerful comparisons between branches or specific points in history. This is essential for understanding differences between branches before merging.

–pretty=format:”": For ultimate control over output, this option allows defining custom formats using placeholders (like %h for abbreviated hash, %an for author name, %s for subject, %ad for author date, etc.). This is particularly useful for scripting or generating custom reports.

Surely, Git log has many more features described in the git-scm.com Documentation.

Conclusion

Git log tells the story of your project’s development journey. This helps find a tricky bug, celebrate a successful feature deployment, or keep an eye on project history. Have fun :)

References

  1. git-scm.com Documentation

Did you like this post? Please let me know if you have any comments or suggestions.

Git posts that might be interesting for you




desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.





Citation
Elena Daehnhardt. (2025) 'Git Log', daehnhardt.com, 24 April 2025. Available at: https://daehnhardt.com/blog/2025/04/24/git-log/
All Posts