Git Logs
๐ Advanced git log Examples
git log is highly customizable. Here are real-world examples:
๐ฆ Basic Commit Log
git logShows full commit history with author, date, and message.
๐งต One-line Log (Condensed View)
git log --onelineShows each commit as a single line: useful for quick scanning.
๐ฒ Visual Branch Graph
git log --oneline --graph --allDisplays 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 -pIncludes 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 --graphThis gives a colorful, structured view:
- Hash in yellow
- Date in green
- Author in cyan
๐ข Limit the Number of Commits
git log -n 5Shows the last 5 commits only.
๐ Stats Per Commit
git log --statDisplays 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"