You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
One of Git's most powerful features is its ability to show you the complete history of a project. You can see every commit ever made, who made it, when, and exactly what changed. This lesson covers the tools Git provides for exploring that history.
The git log command shows the commit history in reverse chronological order (newest first):
git log
Each entry shows the full SHA hash, author, date, and commit message. Press q to exit the pager.
For a condensed overview, use the --oneline flag:
git log --oneline
Each commit appears on a single line with an abbreviated SHA and the commit subject. This is ideal for getting a quick sense of recent activity.
When working with branches, the --graph flag draws an ASCII art representation of the branch and merge history:
git log --oneline --graph --all
The --all flag includes all branches, not just the current one.
Git log supports powerful filtering options:
# Commits by a specific author
git log --author="Alice"
# Commits from the last two weeks
git log --since="2 weeks ago"
# Commits affecting a specific file
git log -- README.md
# Search commit messages for a keyword
git log --grep="login"
To see the full details of a single commit — including the diff it introduced — use git show:
git show abc1234
Replace abc1234 with any abbreviated or full SHA. You can also use HEAD to refer to the most recent commit:
git show HEAD
To see what changed between two commits, use git diff with two SHAs or branch names:
git diff abc1234 def5678
git blame shows you which commit last modified each line of a file — useful for understanding why a particular piece of code was written:
git blame README.md
To find all commits that introduced or removed a particular string anywhere in the code:
git log -S "functionName"
This is called a pickaxe search and is invaluable for tracking down when a function or variable was introduced or deleted.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.