113

Suppose your git commit history looks like this:

A---B---C---D---E---F master
     \         /
      X---Y---Z topic

Is it possible to have git list only the commits on master, A-F? In other words, if the commit was on a merged-in branch, I don't want it show.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
wch
  • 4,069
  • 2
  • 28
  • 36
  • 2
    So, how would git know which of `D` and `Z` was part of the merged branch? – Romain Apr 20 '12 at 14:53
  • 2
    When merged from master, previous master commits are the first parents in merge. `git log` allows to display only those commits with `--first-parent`, so you get the right stuff – CharlesB Apr 20 '12 at 14:56
  • possible duplicate of [How Do I run Git Log to see changes only for a specific branch?](http://stackoverflow.com/questions/4649356/how-do-i-run-git-log-to-see-changes-only-for-a-specific-branch) – Steve Chambers Nov 06 '13 at 09:18

4 Answers4

153

git log has option --first-parent, so you won't get topic history.

When merged from master, the master commits are the first parents in merge. Git log allows to display only those commits with --first-parent, so you get the right stuff.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
26

TLDR : git log origin/master --no-merges will give you a log of master and exclude any merged commits ( in this case x, y, z )

Original Points

There is another general way to go about this that doesn't rely on --first-parent which will be helpful in certain situations.. using the branch exclusion filters

git log origin/topic ^origin/master This will give you a log of origin/topic with all of origin/master's commits removed.

you could also add in --no-merges which will hide merge commits which you may or may not want.

Another handy tip is to use shortlog instead of log which will give you more of an abbreivated summary that can be handy for release notes, or communication of whats in a branch.

Update
After re-reading this, you actually would want nearly the inverse of what I posted; however it would end up excluding everything that is on master and foo ( git log origin/master ^origin/foo ) . However you could also get what you ask for ( hide all commits that are part of merges) with git log origin/master --no-merges

UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
0

Answer by Charles works for me.

git log has option --first-parent --no-merges, so you won't get topic history.

But If you are using any graphic user interface for your Git activities like, Git Extension, SourceTree, Tortoise Git,

Then there are direct options to check the first parent in your tools. I thought to add this answer to the list as most the people find Graphic Interface easy. and You can directly cherry pick all the commits from that particular branch from tool, if required.

I have attached the example of two tools, It would be similar for other tools as well: [I have blured the username, git repo name as this is a private repository, but still you can get an idea how to use first parent from tools]

  1. Git Extension
    • Open Git Extension -> Checkout the feature branch you want to see the commits, there is a option to select first commits as shown in Image:

enter image description here

  1. Tortoise Git
    • Open the repository folder -> Click on Show logs from Tortoise Git -> Checkout the branch and select first commits as shown in Image

enter image description here

KushalSeth
  • 3,265
  • 1
  • 26
  • 29
-4

Does this not work?

git log master
git log --stat master
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
  • No those don't work. The merge commit has two parents; everything tracking back from both of those parents is on the 'master' branch. – GoZoner Apr 21 '12 at 04:27