How to See Merge History in Git: Commands and Examples
To see merge history in Git, use
git log --merges which shows only merge commits. You can add --graph to visualize the branch merges in a tree-like format.Syntax
The main command to see merge commits is git log --merges. Here:
git logshows commit history.--mergesfilters to show only merge commits.--graphadds a visual branch structure.--onelineshows each commit in a single line for brevity.
bash
git log --merges git log --merges --graph --oneline
Example
This example shows how to list merge commits with a graph and short commit messages for easy reading.
bash
git log --merges --graph --onelineOutput
* 9fceb02 Merge branch 'feature'
|\
| * 7ac9a67 Add new feature
* | 3a1b2c4 Fix bug in main
|/
* 1d2f3e4 Initial commit
Common Pitfalls
Some common mistakes when checking merge history:
- Using
git logwithout--mergesshows all commits, making merges hard to spot. - Not using
--graphcan make it difficult to understand branch structure visually. - Confusing merge commits with regular commits; merge commits have two or more parents.
bash
git log # vs git log --merges --graph --oneline
Quick Reference
| Command | Description |
|---|---|
| git log --merges | Show only merge commits in history |
| git log --merges --graph | Show merge commits with branch graph |
| git log --merges --graph --oneline | Show merge commits with graph and short messages |
| git log --first-parent | Show commits from main branch ignoring merges from side branches |
Key Takeaways
Use
git log --merges to filter and see only merge commits.Add
--graph to visualize branch merges clearly.Use
--oneline for a concise summary of merge commits.Without
--merges, merge commits blend with all commits.Merge commits have multiple parents, indicating combined branches.