0
0
GitHow-ToBeginner · 3 min read

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 log shows commit history.
  • --merges filters to show only merge commits.
  • --graph adds a visual branch structure.
  • --oneline shows 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 --oneline
Output
* 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 log without --merges shows all commits, making merges hard to spot.
  • Not using --graph can 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

CommandDescription
git log --mergesShow only merge commits in history
git log --merges --graphShow merge commits with branch graph
git log --merges --graph --onelineShow merge commits with graph and short messages
git log --first-parentShow 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.