How to See Commit History in Git: Simple Commands Explained
To see commit history in Git, use the
git log command in your terminal. This shows a list of commits with details like commit ID, author, date, and message.Syntax
The basic command to view commit history is git log. You can add options to customize the output:
git log: Shows full commit details.git log --oneline: Shows each commit in one line with short ID and message.git log -n 5: Shows the last 5 commits.
bash
git log git log --oneline git log -n 5
Example
This example shows how to use git log --oneline to see a simple list of recent commits.
bash
git log --onelineOutput
a1b2c3d Fix typo in README
4e5f6g7 Add new feature
8h9i0j1 Update dependencies
2k3l4m5 Initial commit
Common Pitfalls
Beginners often forget to run git log inside a Git repository folder, which causes errors. Also, the output can be overwhelming if you have many commits, so using options like --oneline or limiting the number of commits with -n helps.
Another mistake is expecting git log to show changes; it only shows commit info. To see changes, use git show <commit-id>.
bash
cd /path/to/non-git-folder git log # Wrong: running outside a git repo causes error # Right: run inside a git repo folder cd /path/to/git-repo git log --oneline -n 3
Quick Reference
| Command | Description |
|---|---|
| git log | Show full commit history with details |
| git log --oneline | Show each commit in one line |
| git log -n 5 | Show last 5 commits |
| git show | Show details and changes of a specific commit |
Key Takeaways
Use
git log to view commit history in your Git repository.Add
--oneline to see a concise list of commits.Limit output with
-n to avoid too much information.Always run Git commands inside a Git repository folder.
Use
git show <commit-id> to see changes in a specific commit.