Basics

Git Log

Viewing Commit History

Git log displays commit history with author and date details.

Introduction to Git Log

The git log command is an essential tool for developers to review and understand the history of a project. It provides a chronological list of commits, showing details such as the author, date, and commit message. This command is invaluable for tracking changes, understanding project evolution, and debugging issues.

Basic Usage of Git Log

To view the commit history, simply navigate to your Git repository directory in your terminal and execute the following command:

The default output of git log is comprehensive, showing the commit hash, author, date, and commit message for each commit. This output can be long for larger projects, but it provides a detailed history of changes.

Customizing Git Log Output

To make the output of git log more manageable, you can customize it using various options:

  • --oneline - Displays each commit on a single line, showing the first seven characters of the commit hash and the commit message.
  • --graph - Adds a graphical representation of the branch and merge history alongside the log.
  • --decorate - Adds references names, such as branches and tags, to the commits.

Combining these options can help you get a clear view of your project's history in a concise format.

Filtering Git Log Output

In many cases, you might need to filter the log output to locate specific changes or authors. Here are some common ways to filter the log output:

  • --author="Author Name" - Show only commits by a specific author.
  • --since="date" and --until="date" - Limit the log output to commits made within a specific date range.
  • --grep="keyword" - Search commit messages for a specific keyword.

This command will list all commits made by "Jane Doe" in 2023 that include "bug fix" in their commit message.

Viewing Specific File History

To view the history of changes to a specific file, use the following command:

Replace <file-path> with the path to the file you are interested in. This command will show a log of commits that have affected that specific file.

Conclusion

The git log command is a powerful tool for understanding the history of your codebase. By customizing and filtering its output, you can efficiently navigate and analyze the evolution of your project.

Previous
Commit
Next
Diff