5

Looking for a git command which displays commits in a branch that are not merged to master yet, preferably with hash, date, author name and comment.

(This probably is a duplicate question but I couldn't find it on SO)

Tarun Gupta
  • 1,629
  • 1
  • 22
  • 39
  • possible duplicate of [Using Git, show all commits that are in one branch, but not the other(s)](http://stackoverflow.com/questions/1710894/using-git-show-all-commits-that-are-in-one-branch-but-not-the-others) – Andrew C Nov 19 '14 at 07:40

2 Answers2

8

To list commits that are not on master but only only on branch:

git log master..branch

It does not matter which branch is checked out, as you specify the range. Git will find the shortest route from master to branch, first going back on master, not printing the commits, and then listing commits when going forward in history towards branch.

The default format of git log contains all the data you wish to see. But I'd use the --decorate option too, to highlight branches and tags.

SzG
  • 12,333
  • 4
  • 28
  • 41
4

Use the ^master syntax to exclude commits visible from master (i.e. those merged to the master branch):

git log branch ^master

The format can be customized using the --format option, e.g. --format="format:%H %ad %an %s"

user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • This solution also works, but difficult to remember that's why I chose the first one Thanks!! – Tarun Gupta Nov 19 '14 at 08:16
  • 2
    @TarunGupta That's fine, the first one is used more often. Interestingly, I find this one easier to remember because it can also be used to view commits from several branches, and exclude several other branches: `git log branch1 branch2 ... ^exclude1 ^exclude2 ...` – user4815162342 Nov 19 '14 at 08:24