codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
📦

Git & GitHub

7 / 63 topics
1Installing Git2Configuring Git3Initializing a Repository4Using git status5Using git add6Using git commit7Using git log8Using git diff
Tutorials/Git & GitHub/Using git log
📦Git & GitHub

Using git log

Updated 2026-04-20
4 min read

Introduction

Git is a powerful version control system that allows developers to track changes in their codebase over time. One of the most essential commands in Git is git log, which provides detailed information about the commit history of a repository. Understanding how to use git log effectively can greatly enhance your ability to navigate and manage your projects.

In this tutorial, we will explore various options and techniques for using git log. We'll cover basic usage, formatting output, filtering commits, and integrating with other tools like GitHub. By the end of this section, you should be able to use git log proficiently to analyze and understand the history of your Git repositories.

Basic Usage

The simplest way to use git log is by running it in your terminal within a Git repository:

git log

This command will display a list of commits, each showing the commit hash, author, date, and message. The output might look like this:

commit 3a6e7b8f9d2c1e4f5a6b7c8d9e0f1a2b3c4d5e6f
Author: John Doe <john.doe@example.com>
Date:   Mon Jan 1 12:34:56 2022 +0000

    Add initial commit

commit 2b1c3d4e5f6a7b8c9d0e1f2g3h4i5j6k7l8m
Author: Jane Smith <jane.smith@example.com>
Date:   Sun Dec 31 23:45:01 2021 +0000

    Fix bug in login form

Explanation of Output Fields

  • Commit Hash: A unique identifier for each commit.
  • Author: The name and email address of the person who committed the changes.
  • Date: The date and time when the commit was made.
  • Message: A brief description of the changes made in the commit.

Formatting Output

Git log provides several options to format the output, making it easier to read and analyze. Here are some commonly used formatting options:

1. Limiting the Number of Commits

You can limit the number of commits displayed using the -n option followed by the desired number:

git log -n 5

This command will show only the last five commits.

2. Showing Commit Statistics

To see statistics about each commit, such as the number of insertions and deletions, use the --stat option:

git log --stat

The output might look like this:

commit 3a6e7b8f9d2c1e4f5a6b7c8d9e0f1a2b3c4d5e6f
Author: John Doe <john.doe@example.com>
Date:   Mon Jan 1 12:34:56 2022 +0000

    Add initial commit

 src/index.js | 10 ++++++++++
 1 file changed, 10 insertions(+)

3. Showing Patch Information

To view the actual changes made in each commit, use the -p option:

git log -p

This command will display a diff for each commit, showing exactly what was added and removed.

Filtering Commits

Git log offers various ways to filter commits based on different criteria. Here are some useful filtering options:

1. Filtering by Author

You can filter commits by the author's name or email using the --author option:

git log --author="John Doe"

This command will show only the commits made by John Doe.

2. Filtering by Date

To filter commits by date, use the --since and --until options:

git log --since="1 week ago" --until="2 weeks ago"

This command will display commits that were made between one and two weeks ago.

3. Filtering by File

You can also filter commits that affected a specific file or directory using the -- option followed by the path:

git log -- src/app.js

This command will show only the commits that modified src/app.js.

Advanced Usage

Git log supports advanced options for more complex queries and customizations. Here are some examples:

1. Customizing Output Format

You can customize the output format using the --pretty option with various formats like oneline, short, full, or fuller. For example, to display each commit in a single line, use:

git log --pretty=oneline

The output might look like this:

3a6e7b8f9d2c1e4f5a6b7c8d9e0f1a2b3c4d5e6f Add initial commit
2b1c3d4e5f6a7b8c9d0e1f2g3h4i5j6k7l8m Fix bug in login form

2. Graphical Representation

To visualize the branch structure and merges, use the --graph option:

git log --graph --oneline --all

This command will display a graphical representation of the commit history, showing branches and merge points.

Best Practices

Here are some best practices for using git log effectively:

  1. Use Aliases: Create aliases for frequently used git log commands to save time. For example:

    git config --global alias.lg "log --oneline --graph --all"
    
  2. Document Commit Messages: Write clear and concise commit messages that describe the changes made. This will make it easier to understand the history of your project.

  3. Regularly Review History: Use git log regularly to review recent changes, especially before merging branches or releasing new versions.

  4. Leverage External Tools: Consider using external tools like tig, SourceTree, or GitHub Desktop for a more graphical and user-friendly interface when reviewing commit history.

Conclusion

Git log is an indispensable tool for any developer working with Git. By mastering its various options and techniques, you can gain valuable insights into the history of your projects and manage them more effectively. Whether you're troubleshooting issues, understanding code changes, or collaborating with others, git log will be a powerful ally in your workflow.

In this tutorial, we covered basic usage, formatting output, filtering commits, and advanced options for customizing the git log command. By applying these concepts, you'll be well-equipped to use git log proficiently and enhance your Git skills.


PreviousUsing git commitNext Using git diff

Recommended Gear

Using git commitUsing git diff