Git log to get commits only for a specific branch


I want to list all commits that are only part of a specific branch.

With the following, it lists all the commits from the branch, but also from the parent (master)

git log mybranch

The other option I found, was to exclude the commits reachable by master and gives me what I want, BUT I would like to avoid the need of knowing the other branches names.

git log mybranch --not master

I was trying to use git for-each-ref, but it is also listing mybranch so actually it is excluding all:

git log mybranch --not $(git for-each-ref --format '^%(refname:short)' refs/heads/)


I'm testing a new option that I found a while ago, and till now seems that this could be what I was looking for:

git log --walk-reflogs mybranch

Update (2013-02-13T15:08):

The --walk-reflogs option is good, but I checked that there is an expiration for reflogs (default 90 days, gc.reflogExpire).

I think I found the answer I was looking for:

git log mybranch --not $(git for-each-ref --format='%(refname)' refs/heads/ | grep -v "refs/heads/mybranch")

I'm just removing the current branch from list of branches available and using that list to be excluded from the log. This way I only get the commits that are only reached by mybranch.


From what it sounds like you should be using cherry:

git cherry -v develop mybranch

This would show all of the commits which are contained within mybranch, but NOT in develop. If you leave off the last option (mybranch), it will compare the current branch instead.

As VonC pointed out, you are ALWAYS comparing your branch to another branch, so know your branches and then choose which one to compare to.

How to move certain commits to be based on another branch in git?

Is it possible to create a remote repo on GitHub from the CLI without opening browser?