Git Logs

๐Ÿ” Advanced git log Examples

git log is highly customizable. Here are real-world examples:


๐Ÿ“ฆ Basic Commit Log

git log

Shows full commit history with author, date, and message.


๐Ÿงต One-line Log (Condensed View)

git log --oneline

Shows each commit as a single line: useful for quick scanning.


๐ŸŒฒ Visual Branch Graph

git log --oneline --graph --all

Displays commit history as a branch graph across all branches.


๐Ÿ“† Log with Dates

git log --pretty=format:"%h - %an, %ar : %s"

Custom format: shows commit hash, author, relative date, and message.


๐Ÿ”Ž Filter by Author

git log --author="nirpendra"

Shows only commits made by a specific author.


๐Ÿ• Commits from the Last 7 Days

git log --since="7 days ago"

Or filter between two dates:

git log --since="2024-06-01" --until="2024-06-30"

๐Ÿ“ Log for a Specific File

git log -- <file-path>

View changes made to a particular file.

Example:

git log -- src/main.py

๐Ÿงพ Show Diff with Each Commit

git log -p

Includes the patch (code changes) with each commit.


๐Ÿงฐ Combined Format: Pretty + Graph + Oneline

git log --pretty=format:"%C(yellow)%h%Creset %Cgreen%ad%Creset %C(cyan)%an%Creset - %s" --date=short --graph

This gives a colorful, structured view:

  • Hash in yellow
  • Date in green
  • Author in cyan

๐Ÿ”ข Limit the Number of Commits

git log -n 5

Shows the last 5 commits only.


๐Ÿ“Š Stats Per Commit

git log --stat

Displays each commit along with the number of lines added/removed and the file names.


๐Ÿ“œ List Files Modified in Last Commit

git log -1 --name-only

๐Ÿ” View Only Merge Commits

git log --merges

๐Ÿ’ก Tip: You can combine these flags for powerful custom outputs! Example:

git log --oneline --author="nirpendra" --since="1 week ago"