How can I compare the commits in one Git branch that are not in another?
Quick answer
To list commits reachable from topic but not from main, run git log main..topic --oneline. The range direction matters: it lists commits on the branch named second that are not reachable from the branch named first. Reverse the names to inspect commits on main that topic lacks. Use git diff when you want to compare file contents instead; it answers a different question. [S1] [S2]
The question, the details, the next step.
A practical checklist
Name the two branches you want to compare.
Put the branch whose commits you want listed second in
git log A..B.Use
--onelinefor a compact commit list, or omit it for the default log display.Reverse the branch names to inspect the other direction.
Use
git diff A Bfor endpoint file-content differences, not for a unique-commit list.
A few more useful answers
What does an empty `git log main..topic --oneline` result tell me?
It means the command found no commits reachable from topic that are absent from main. It does not by itself establish that the branches’ file contents are identical.
Should I use `git diff main...topic` to list commits unique to `topic`?
How do I see commits unique to both branches?
Run git log main..topic --oneline and git log topic..main --oneline. Each range lists commits from its second branch that are not reachable from its first. [S1]
Sources
References used for this guide.
- [S1] Git git-log documentation: commit ranges git-scm.com · Checked
- [S2] Git git-diff documentation: comparing commit endpoints git-scm.com · Checked
