A Comprehensive Guide to Using Git Log Command

A Comprehensive Guide to Using Git Log Command

Git is a popular version control system used for software development projects. Git log is a command that helps developers to view the commit history in a repository. It shows the commit hash, author, date, and commit message. In this article, we will discuss in detail how to use Git log command in your workflow.

Basic Command Syntax

The basic syntax of Git log command is:

git log [options]

Here, options refer to the parameters that modify the output of the command. The most commonly used options are:

  • -p : Show the differences introduced in each commit.
  • --stat : Show the statistics of modified files in each commit.
  • --oneline: Show each commit on a single line.
  • --graph: Show a graph of the commit history.
  • --decorate: Show branch and tag names of each commit.

Viewing the Commit History

To view the commit history of a repository, run the Git log command without any parameters:

git log

By default, Git log command shows the latest commits first. Each commit is displayed with the following information:

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

Here is an example output of Git log command:

commit c5f5cd5c6b92309ccab2d26d33afeb0eb89fba43
Author: John Doe <john@example.com>
Date:   Tue Mar 23 10:14:40 2021 +0530

    Fix typo in README

commit 85918d5462938db835110a1fb4041f7d15a361a8
Author: Jane Doe <jane@example.com>
Date:   Mon Mar 22 11:20:05 2021 +0530

    Add a new feature

Limiting the Number of Commits

Sometimes, the commit history can be too long to view all at once. In this case, you can limit the number of commits displayed using the -n option:

git log -n 5

This command will display the latest five commits. Change the number as per your requirement.

Filtering the Commits by Author

You can use the --author option to filter the commit history by the author’s name or email address. For example, to view the commits made by John Doe, run the following command:

git log --author="john@example.com"

This command will display all commits made by John Doe.

Filtering the Commits by Time

You can also filter the commit history by the time range using the --since and --until options. For example, to view the commits made between two dates, run the following command:

git log --since="2021-03-21" --until="2021-03-24"

This command will display all commits made between 21st and 24th March 2021.

Viewing the Diff of Commits

To view the difference or changes made in a commit, use the -p option. For example, to view the changes made in the latest commit, run the following command:

git log -p -1

This command will display the changes made in the latest commit in a detailed format.

Viewing the Statistics of Changes

You can also view the statistics of changes made in each commit using the --stat option. This option shows the number of lines added and deleted in each file. For example, to view the statistics of changes in the latest commit, run the following command:

git log --stat -1

This command will display the statistics of changes made in the latest commit.

Viewing the Graph of Commit History

To visualize the commit history in a graphical format, use the --graph option. This option shows a diagram of the branch and merge history. For example, to view the graph of commit history, run the following command:

git log --graph

This command will display a graphical representation of the commit history.

Viewing the Branches and Tags

You can view the branches and tags of each commit by using the --decorate option. This option shows the branch and tag names of each commit. For example, to view the branches and tags of each commit, run the following command:

git log --decorate

This command will display the branch and tag names of each commit.

Conclusion

With this detailed guide to using Git log command, you can easily view and analyze the history of a Git repository. Using the various options and filters of the command, you can get the specific information you need to understand the progress of a project. Happy coding!

Like(0)

Related

Git Tutorials
Git TutorialDifferences between Git and SVNGit vs. Github: What's the Difference?How to Install Git on WindowsHow to Install Git on LinuxHow to Install Git on MacConfiguring Git on Your Local EnvironmentGit Workflow Detailed ExplanationGit Basic Commands IntroductionGit add command detailed explanationGit amend Command: A Comprehensive GuideA comprehensive guide to Git apply commandGit branch Command: A Comprehensive GuideGit Blame command: A detailed explanationGit Config Command in DetailGit clone Command: A Detailed ExplanationA Comprehensive Guide to the Git Clean CommandUnderstanding and Using Git Commit CommandA Comprehensive Guide to Git Checkout commandGit cherry-pick Command: A Comprehensive Guide to Its UsageA Detailed Guide to Git Diff CommandGit Fetch Command: A Comprehensive GuideA Comprehensive Guide to Git Format-Patch CommandGit ignore Command: A Detailed GuideGit init Command: A Comprehensive GuideA Comprehensive Guide to Using Git Log CommandGit merge command tutorialA Comprehensive Guide to Using Git mv CommandGit push command: A Detailed Guide on Using itA Comprehensive Guide to Using Git Pull CommandGit remote command usageGit Revert Command Detailed ExplanationGit reset Command: A Comprehensive GuideGit Restore Command: A Comprehensive GuideA Comprehensive Guide to Git Rebase CommandGit reflog Command Usage ExplainedGit rm Command Usage OverviewGit Status Command - A Detailed GuideDetailed Explanation of Git Stash CommandGit show Command: An In-depth GuideGit Switch Command: A Comprehensive GuideComplete Guide to Using Git Tag CommandGit .gitignore File: A Comprehensive Guide