How to Check Commit History in Git

Viewing your commit history is essential to understand the changes made over time in a Git repository. Git provides powerful commands to review past commits, their authors, messages, and more.


🔍 Common Ways to View Commit History

1. Basic Commit Log

Run this command to see a simple list of commits:

git log

This shows commits in reverse chronological order, including:

  • Commit hash (unique ID)
  • Author name & email
  • Date
  • Commit message

2. One-line Summary of Commits

For a concise overview:

git log --oneline

Output example:

a1b2c3d Fix header layout
e4f5g6h Add login feature
...

Each commit is shown as a short hash plus message.


3. Pretty Format and Graph View

To visualize branches and merges:

git log --graph --oneline --all --decorate
  • --graph shows the branch structure with ASCII art
  • --all shows all branches
  • --decorate shows branch and tag names

4. Limit the Number of Commits

To see only the last 5 commits:

git log -5

5. View Changes in Each Commit

To see diffs introduced by each commit:

git log -p

🧠 Tips for Browsing History

  • Use arrow keys to scroll through git log output; press q to quit
  • Combine with grep to search commit messages: git log --grep="bug fix"
  • Check history of a specific file: git log -- filename.txt

Summary Table

CommandDescription
git logShow detailed commit history
git log --onelineShow compact commit list
git log --graph --oneline --allShow visual graph of commits and branches
git log -5Show last 5 commits
git log -pShow diffs introduced by commits
Sharing Is Caring:

Leave a Comment