Git Tutorial
- 1. Introduction to Git & VCS
- 2. Installation & Configuration
- 3. Git Architecture & Concepts
- 4. Basic Workflow (add/commit)
- 5. Git Log & History
- 6. Branching Basics
- 7. Merging & Conflict Resolution
- 8. Git Rebasing
- 9. Undoing Changes
- 10. Working with Remotes
- 11. Git Stashing
- 12. Git Tagging
- 13. Git Ignore & Attributes
- 14. Advanced Git Tools
- 15. Best Practices & Workflows
5. Git Log & Commit History
One of the greatest benefits of a Version Control System is the ability to travel back in time and view your project's evolution. In Git, the primary tool for reviewing this history is git log, along with git show to inspect details of a specific point in time.
The Standard Log Command
Running the basic log command with no arguments prints all commits made in the repository in reverse chronological order:
git logFor each commit, this prints:
- The full 40-character SHA-1 checksum hash.
- The Author name and email.
- The Date and time when the commit was created.
- The descriptive Commit Message.
Formatting Commit Histories
As a project grows, the default git log output can become very long and difficult to scan. Git provides highly useful formatting flags to condense and visualize history.
1. Compact Single-Line: --oneline
Condenses each commit into a single line showing only the first 7 characters of the SHA-1 hash and the commit subject line:
git log --onelineExample Output:
a8f1b2c Add contact form component
2b3d9e4 Fix typo in landing page navbar
e77b0c1 Initial commit with project framework2. Interactive Tree Graph: --graph
Draws an ASCII graph representing the branch history, showing where branches split and merged:
git log --graph --onelineExample Output:
* 7f8e9a2 (HEAD -> main) Merge branch 'feature/contact'
|\
| * a8f1b2c (feature/contact) Add contact form component
| * 4d9e0b1 Design form fields and validation rules
* | 2b3d9e4 Fix typo in landing page navbar
|/
* e77b0c1 Initial commit with project framework3. Displaying branch/tag references: --decorate
Shows all branch references (like HEAD, main, feature/login) and release tags next to the commits. This is usually enabled by default in modern Git versions.
Filtering Commit History
If you need to find a specific commit in a crowded repository, you can filter logs in highly specific ways:
| Filter Goal | Git Command |
|---|---|
| Limit number of commits | git log -n 5 (Shows only the latest 5 commits) |
| Filter by Author | git log --author="John Doe" |
| Filter by Date range | git log --since="2 weeks ago" --until="yesterday" |
| Filter by Search term | git log --grep="bugfix" (Searches commit messages) |
| Filter by File path | git log -- package.json (Shows commits affecting only this file) |
Inspecting a Commit: git show
To examine the exact content changes and metadata details of a specific commit, use git show followed by a commit hash:
# Inspect the latest commit (HEAD)
git show
# Inspect a specific commit using its short hash
git show a8f1b2cThis prints the author, date, commit message, and the full unified diff of all file changes in that commit.
git config --global alias.adog "log --all --decorate --oneline --graph"Now, typing git adog will give you a stunning visual representation of all commits and branches!