git log — Viewing Commit History
The git log command shows the history of commits in your repository. It's how you look back at what happened, who did it, and when.
Reading the Log
When you run git log, each entry shows:
- Commit hash — The full SHA identifier (e.g.,
a1b2c3d4e5f6...) - Author — Name and email of the person who made the commit
- Date — When the commit was created
- Message — The description the author wrote
The log is displayed in reverse chronological order — newest commits first.
Useful Flags
--oneline
Condenses each commit to a single line showing just the short hash and message:
git log --oneline
Output looks like:
a1b2c3d Add second file
f4e5d6a Add first file
9b8c7d6 Initial commit
-n (limit)
Show only the last N commits:
git log -3
--all
Show commits from all branches, not just the current one:
git log --oneline --all
Try it!
The repository is already initialized. Create three commits and explore the log:
- Create a file:
echo "hello" > hello.txt - Stage and commit:
git add hello.txtthengit commit -m "Add hello file" - Create another file:
echo "world" > world.txt - Stage and commit:
git add world.txtthengit commit -m "Add world file" - Create a third file:
echo "!" > exclaim.txt - Stage and commit:
git add exclaim.txtthengit commit -m "Add exclaim file" - View the full log:
git log - View the compact log:
git log --oneline
Notice how --oneline gives you a quick overview while the full log has all the details.
Searching the Log
You can also filter commits by author or message content:
git log --author="Alice"
git log --grep="fix"
These become invaluable as your project history grows.