git diff showing only commits that revision/branch A is ahead of revision/branch B

I think the right answer is triple dot

git diff master...feature

That shows only new changes on feature with respect to master. See also: git diff - show only what's new on the remote


I usually go for

git log -p feature-branch --not master

But if you want a diff, you're looking for

git diff <common-ancestor> master

where <common-ancestor> is a common ancestor of your feature branch and master that you want to compare to. You can use merge-base to find that for you.

git diff `git merge-base feature-branch master` feature-branch

Your question is a little unclear because I'm not sure if you want to see a diff/patch of the changes between master and feature, or you just want to see which branches contain which commits that the other branch doesn't have.

Assuming that you just want to see what commits are in your feature branch that don't exist in master (i.e. which commits in feature are "ahead" of master), then you can do

$ git log --oneline --graph master..feature

If you want to see how both master and feature have diverged, you can use this command:

$ git log --oneline --graph --first-parent \
--decorate --left-right master...feature
> 5bef654 (feature) A ...
> f7c65ea B ...
> fc66245 C ...
> 7435fc0 D ...
< bf68204 (master) X ...
< 0c10ed1 Y ...
< 27bb774 Z ...

The above output shows commits in master that are not in feature with < in front of them (since you used master...feature with master on the left < side of the command), while commits in feature that aren't in master are marked with > since you used feature on the right side of master...feature. The triple dots ... in this form are important, don't leave them out.

You can learn more about specifying Commit Range from the Pro Git book.