Search code examples
gitbranchcommitdifference

Show commits on local branch A that local branch B has not


I've already read that there is

$ git checkout B
$ git cherry -v A

but this produces nothing for me and I suppose that this (and some other similar command, I think git log B ^A, which does actually output some differences, but somehow did not show all the different commits) only applies for the case of B being the remote tracking branch of A.

But I want to compare two local branches' commits, so how do I do this?

Update: To be more verbose, I tried

git log B..A

and

git log B ^A

but HEAD from A did not show up, although it wasn't on B.

EDIT: Not sure anymore, if I did the git cherry the wrong way around, I probably made a mistake, so it should actually work


Solution

  • If you want to show all commits reachable from A, but exclude those reachable from B:

    git log A ^B # read: A, but *not* B
    

    or, more in line with the general usage of git log:

    git log B..A # read: show history from B to A
    

    Behavior of both commands is identical (both refspecs describe the same commits)