git
branches
commit differences
version control
git commands

How do I see the commit differences between branches in git?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

When you want to compare branches in Git, you need to decide whether you care about commit history, file content, or both. For commit-level differences, git log with branch ranges is usually the best tool; for line-by-line code changes, git diff is better.

Most confusion comes from using the right command with the wrong comparison syntax. Once you understand branch ranges, Git becomes much more predictable.

Show Commits in One Branch but Not the Other

To see commits that are in feature but not in main, run:

bash
git log main..feature --oneline

Read this as “show me commits reachable from feature that are not reachable from main.” This is the most common answer when someone asks for commit differences between two branches.

To reverse the question, swap the branches:

bash
git log feature..main --oneline

That gives the opposite set.

See Both Sides at Once with --left-right

If you want one report showing commits unique to each branch, use the symmetric difference form with three dots.

bash
git log --left-right --oneline main...feature

Git marks which side each commit comes from. This is useful before a merge because it shows both branch histories relative to their merge base.

Compare the Code Changes, Not Just the Commit List

If the question is really “what content changed between these branches?” then use git diff.

bash
git diff main..feature

That prints the patch difference between the tips of the two branches.

A narrower summary is often easier to read first:

bash
git diff --stat main..feature

Use git log to understand history. Use git diff to understand the resulting code difference.

Use the Merge Base When You Want Review-Style Output

A common review scenario is: “show me what feature introduced since it diverged from main.” The three-dot form is often what you want there.

bash
git diff main...feature

This compares the merge base against feature, which is closer to what code review tools show for a pull request.

That is different from main..feature, which compares the two branch tips directly.

A Small Example

Suppose:

  • 'main has commits A -> B -> C'
  • 'feature branched from B and added D -> E'

Then:

bash
git log main..feature --oneline

shows D and E.

And:

bash
git diff main...feature

shows the content changes introduced by feature since the split point at B.

Useful Add-Ons

These flags help in practice:

bash
git log main..feature --oneline --decorate --graph

That makes the branch relationship easier to read.

If you need only commit subjects that mention a topic:

bash
git log main..feature --grep="refactor" --oneline

You can also compare specific files:

bash
git diff main...feature -- src/api/

Common Pitfalls

  • Using git diff when you actually want a list of commits, or git log when you actually want file changes.
  • Confusing .. and .... They answer different questions.
  • Forgetting which direction the range is written in, which reverses the meaning of the output.
  • Comparing branch tips directly when a merge-base comparison would better match code review intent.
  • Assuming commit differences and content differences are the same thing. Rebases and cherry-picks can make them diverge.

Summary

  • Use git log branch1..branch2 to see commits in branch2 but not in branch1.
  • Use git log --left-right branch1...branch2 to see both sides relative to the merge base.
  • Use git diff when you care about code changes rather than commit objects.
  • Three dots are often the better choice for review-style comparisons.
  • Always decide first whether you want history, content, or both.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.