Git: How to list commits on this branch but not from merged branches
Solution 1
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.
Solution 2
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
Related videos on Youtube
wch
Updated on October 27, 2020Comments
-
wch over 3 years
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.
-
Romain about 12 yearsSo, how would git know which of
D
andZ
was part of the merged branch? -
CharlesB about 12 yearsWhen 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 -
Steve Chambers over 10 yearspossible duplicate of How Do I run Git Log to see changes only for a specific branch?
-
-
c00kiemon5ter about 12 years+1
--first-parent
does it :) combined with--no-merges
you can hide the merge commits -
GoZoner about 12 yearsNo those don't work. The merge commit has two parents; everything tracking back from both of those parents is on the 'master' branch.