git log

Estimated reading: 2 minutes 17 views

The git log command shows the history of commits in your repository. It provides details like commit hashes, authors, dates, and messages. You can customize the output with various options.

Optional Commands with git log

You can enhance the functionality of git log by using the following optional flags:

OptionDescriptionExample
-n <number>Limits the number of commits displayed.git log -n 5 shows the last 5 commits.
--onelineCondenses commit details into a single line.git log --oneline provides a brief history with commit hashes and messages.
-pDisplays the changes (diffs) introduced in each commit.git log -p shows detailed differences for each commit.
--author="<name>"Filters commits by author.git log --author="Jane Doe" lists commits made by Jane Doe.
--since and --untilFilters commits by a date range.git log --since="2024-12-01" --until="2024-12-10" shows commits within that date range.
-- <file>Displays the history of a specific file.git log -- example.txt lists all commits affecting example.txt.

Syntax and Example

				
					# Basic usage: View full commit history in detail
git log
# Example output:
# commit abc1234567890def1234567890abcdef12345678
# Author: Jane Doe <jane.doe@example.com>
# Date:   Mon Dec 10 14:32:00 2024 -0500
#
#     Added login functionality

# Show only the last 3 commits
git log -n 3
# Example output (most recent 3 commits):
# commit abc1234 Added login functionality
# commit def5678 Fixed a bug in the logout feature
# commit ghi9012 Updated documentation

# Condensed view: Show commit hashes and messages on one line
git log --oneline
# Example:
# abc1234 Added login functionality
# def5678 Fixed logout bug
# ghi9012 Updated docs

# Show changes made in each commit (patch mode)
git log -p
# Example output includes diffs of changes in each commit.

# Filter by author to see commits made by Jane Doe
git log --author="Jane Doe"
# Example output:
# Shows commits only authored by Jane Doe.

# View the history of a specific file
git log -- example.txt
# Example:
# Shows all commits that modified example.txt.

				
			

Summary Note

  • Purpose: The git log command is primarily used to review a repository’s commit history. It helps you:
    • Understand Changes: See what was modified, when, and by whom.
    • Debug Issues: Pinpoint specific changes by filtering commits by author, file, or content.
    • Collaborate Effectively: Review detailed histories and coordinate with team members.

By using options like --oneline, -n, and --author, you can tailor the output to your specific needs, making git log an essential tool for understanding project history and tracking progress.

Leave a Comment

Share this Doc

git log

Or copy link

CONTENTS