Git: How to list commits on this branch but not from merged branches

前端 未结 4 1203
小蘑菇
小蘑菇 2020-12-02 09:58

Suppose your git commit history looks like this:

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

Is it possible to hav

4条回答
  •  时光取名叫无心
    2020-12-02 10:11

    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

提交回复
热议问题