Tracking your project’s progress and understanding changes over time is key to effective version control. Git makes it easy to view the commit history of a repository so you can see who changed what, when, and why.
In this guide, you’ll learn how to get commit history using simple and powerful Git commands.
✅ View Commit History with git log
The most basic and commonly used command:
git log
This displays a list of commits in reverse chronological order (most recent first), showing:
- Commit hash
- Author
- Date
- Commit message
Example output:
commit e4e23dfc7d6a7c987c9abf26f3214c1ab58b8c42
Author: John Doe <jo**@ex*****.com>
Date: Mon May 13 14:30:00 2024 +0530
Fix typo in README
✅ Customize the Output
You can make git log
more readable or tailored to your needs:
One-line format:
git log --oneline
Displays a simplified log with just the commit hash and message.
Graph view (shows branches and merges):
git log --oneline --graph --all
Visualizes the commit tree and branch structure.
Include file changes:
git log -p
Shows the diff of each commit.
✅ View Commit History for a Specific File
To see the history of changes to a single file:
git log path/to/your/file.txt
Add -p
to also see what changed:
git log -p path/to/your/file.txt
✅ Short Summary Format
To get a concise summary:
git log --pretty=format:"%h - %an, %ar : %s"
This shows:
- Commit hash
- Author name
- Relative date
- Commit message
Example:
a1b2c3d - Alice, 3 days ago : Add login feature
🧩 Summary of Common Commands
Task | Command |
---|---|
View full commit history | git log |
View in one-line format | git log --oneline |
View with graph | git log --oneline --graph --all |
View changes in each commit | git log -p |
View history for a specific file | git log path/to/file |
Custom summary format | git log --pretty=format:"..." |
📌 Final Tips
- Use
q
to exit the log view when it opens in a pager (likeless
). - Combine
git log
withgrep
to search commit messages:
git log --grep="bug fix"
- Use GUI tools like GitKraken, Sourcetree, or GitHub Desktop for visual commit histories.