๐ŸŽ‰ Special Offer !    Code: GET300OFF    Flat โ‚น300 OFF on every Java Course
Grab Deal ๐Ÿš€

View Commit History in Git - git log


Introduction

  • git log command is used to view the commit history of a Git repository.
  • It displays a list of commits in reverse chronological order, showing the most recent commits first.
  • git log command helps in tracking the project's evolution, understanding code changes, and identifying contributors.

How to use git log ?

  • Check your logs:
    • git log
  • The command will show the following:
    • Git Log Command
  • Each commit entry shows:
    • Commit hash (a unique identifier)
    • Author name and email
    • Date and time of the commit
    • Commit message explaining the change.

Different ways to use git log ?

  1. View Detailed Commit History:
    • git log
    • Shows complete commit history with author, date, and message.
    • Useful for a deep analysis of project history.
  2. View a Compact History:
    • git log --oneline
    • Displays each commit in a single line with a short hash and commit message.
    • Ideal for a quick overview.
  3. View Specific Number of Commits:
    • git log -n 5
    • Shows the last 5 commits.
    • Useful when you want to see recent changes only.
  4. View History for a Specific File:
    • git log filename.txt
    • Displays the commit history of a specific file.
    • Helps track changes made to that particular file.
  5. View History with File Differences:
    • git log -p
    • Shows commit history along with the actual changes (diffs).
    • Useful for detailed code reviews.
  6. View Commits by a Specific Author:
    • git log --author="Author Name"
    • Filters commits by a specific author.
    • Useful for reviewing individual contributions.
  7. View History with Date Range:
    • git log --since="2024-01-01" --until="2024-12-31"
    • Shows commits within a specific time range.
    • Helpful for tracking progress during a period.
  8. Graphical Log View:
    • git log --graph --oneline
    • Shows a visual representation of branches and merges.
    • Great for understanding complex commit histories.
  9. Search Commit Messages:
    • git log --grep="bug fix"
    • Filters commits by keywords in commit messages.
    • Useful for finding commits related to specific tasks.
  10. Show Changes Introduced by Each Commit:
    • git log --stat
    • Summarizes the number of changes (lines added/removed) per file.
    • Quick way to understand the impact of each commit.