threads / discuss / 21968

How do I show only log messages for commits on a specific branch?

Subject: How do I show only log messages for commits on a specific branch?

## tl;dr

10 messages between Dec 16, 2009 and Dec 17, 2009.

replies: 9people: 6as markdown or json

bd@bc-bd.org· Dec 16, 2009, 10:16 UTC · lore
Hello list,
[ git v1.6.3.3 ]
imagine this:
	     --A--*--B (new)
	    /
	*--X--*--Y (master)
Now I'd like to list only log messages for A..B (X..B would be okay too).
I know of 
	git log master..new

however then I need to remember that I branched new of master, and to be honest, sometimes I forget.

So how do I:
	git please-tell-me-the-branch-I-started-this-branch-from new
Thanks in advance,
	Stefan
-- 
BOFH excuse #181:

Atilla the Hub
Elijah Newren· Dec 16, 2009, 18:05 UTC · re: bd@bc-bd.org · lore

Re: How do I show only log messages for commits on a specific branch?

On Wed, Dec 16, 2009 at 3:16 AM,  <bd@bc-bd.org> wrote:
Show 18 quoted lines
> imagine this:
>
>             --A--*--B (new)
>            /
>        *--X--*--Y (master)
>
> Now I'd like to list only log messages for A..B (X..B would be okay too).
>
> I know of
>
>        git log master..new
>
> however then I need to remember that I branched new of master, and to be honest,
> sometimes I forget.
>
> So how do I:
>
>        git please-tell-me-the-branch-I-started-this-branch-from new
In the above example, you technically did not create 'new' off of
'master', you created new starting at X.  You may think of it in terms
of branching off of 'master', but
  git branch new master
resolves 'master' to the commit it points at and creates 'new'
pointing at that commit.  That's all that is recorded.  But I believe
the info you are really interested in is where new started, rather
than the fact that it branched off master.  Is that correct?  If so,
just use new@{30.years.ago} (or any other sufficiently long period of
time):
  git log new@{30.years.ago}..new
(You'll get a warning that 'new' hasn't existed for 30 years but it
doesn't hurt anything)

Hope that helps, Elijah

Miklos Vajna· Dec 16, 2009, 23:26 UTC · re: Elijah Newren · lore

Re: How do I show only log messages for commits on a specific branch?

On Wed, Dec 16, 2009 at 11:05:52AM -0700, Elijah Newren <newren@gmail.com> wrote:
>   git log new@{30.years.ago}..new
> (You'll get a warning that 'new' hasn't existed for 30 years but it
> doesn't hurt anything)
That's the same as "git log new", if I'm not mistaken.

What Stefan wants to do is to let git log show the commits which are only in the "new" branch, but I don't think there is an out-of-the-box solution for that.

One solution I can think of is to iterate over each ref using "git for-each-ref --format='%(refname)' 'refs/heads/*'", then run "git merge-base $i new", run git rev-list $mb..new|wc -l and then you could decide what is the first commit that does not belong to any other branch. But that's just an idea, I don't have the motivation to script it properly.

Santi Béjar· Dec 16, 2009, 23:58 UTC · re: Miklos Vajna · lore

Re: How do I show only log messages for commits on a specific branch?

On Thu, Dec 17, 2009 at 12:26 AM, Miklos Vajna <vmiklos@frugalware.org> wrote:
Show 10 quoted lines
> On Wed, Dec 16, 2009 at 11:05:52AM -0700, Elijah Newren <newren@gmail.com> wrote:
>>   git log new@{30.years.ago}..new
>> (You'll get a warning that 'new' hasn't existed for 30 years but it
>> doesn't hurt anything)
>
> That's the same as "git log new", if I'm not mistaken.
>
> What Stefan wants to do is to let git log show the commits which are
> only in the "new" branch, but I don't think there is an out-of-the-box
> solution for that.

Not out-of-the-box but this does exactly what you said, print all commits only reachable from the "new" branch:

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

For the original question, I think what makes most sense in this case is asking for the commits since the upstream branch. Some time ago there was a discussion about a syntax for the tracking branch and there was even a patch:

Subject: [PATCH v2] Introduce <branch>@{upstream} as shortcut to the
tracked branch
Date: 2009-09-10 15:25:57 GMT
http://news.gmane.org/find-root.php?message_id=%3calpine.DEB.1.00.0909101724520.8306%40pacific.mpi%2dcbg.de%3e
but it's not in git.git.

HTH, Santi

Elijah Newren· Dec 17, 2009, 00:04 UTC · re: Santi Béjar · lore

Re: How do I show only log messages for commits on a specific branch?

On Wed, Dec 16, 2009 at 4:58 PM, Santi Béjar <santi@agolina.net> wrote:
> git log new --not $(git for-each-ref --format='%(refname)'
> 'refs/heads/*' | grep -v refs/heads/new)
How did I miss '--not' as a git log option?  Thanks for pointing it out!
Elijah Newren· Dec 16, 2009, 23:59 UTC · re: Miklos Vajna · lore

Re: How do I show only log messages for commits on a specific branch?

On Wed, Dec 16, 2009 at 4:26 PM, Miklos Vajna <vmiklos@frugalware.org> wrote:
Show 6 quoted lines
> On Wed, Dec 16, 2009 at 11:05:52AM -0700, Elijah Newren <newren@gmail.com> wrote:
>>   git log new@{30.years.ago}..new
>> (You'll get a warning that 'new' hasn't existed for 30 years but it
>> doesn't hurt anything)
>
> That's the same as "git log new", if I'm not mistaken.

Did you try it with a 'new' branch in your repository that started at the beginning of history rather than at some commit? "git log new" and "git log new@{30.years.ago}..new" are not the same for me with git-1.6.5.5:

$ git init repo
$ cd repo
$ echo content> foo && git add foo && git commit -mone foo
$ echo more content >> foo && git commit -mtwo foo
$ git checkout -b new master~1
$ echo stuff >> foo && git commit -mthree foo
$ git log new@{30.years.ago}..new
warning: Log for 'new' only goes back to Wed, 16 Dec 2009 16:48:02 -0700.
commit 7df8bad7cc146875c59ab030da0d25555976e79c
Author: Elijah Newren <newren@gmail.com>
Date:   Wed Dec 16 16:48:07 2009 -0700
    three
$ git log new
commit 7df8bad7cc146875c59ab030da0d25555976e79c
Author: Elijah Newren <newren@gmail.com>
Date:   Wed Dec 16 16:48:07 2009 -0700
    three
commit b86eadcdb152877ade44bebf4b8742884949f29f
Author: Elijah Newren <newren@gmail.com>
Date:   Wed Dec 16 16:47:31 2009 -0700
    one
> What Stefan wants to do is to let git log show the commits which are
> only in the "new" branch, but I don't think there is an out-of-the-box
> solution for that.

Are you sure? I'm more inclined to believe he'd like to see all the commits that have been added to the "new" branch since he created it (which may be the same as what you say, but not necessarily). Of course, neither my assumption or yours match what he actually asked for (though I think what he asked for isn't possible and is merely an means to the end he really wants).

Also, I think this does what you asked for (the commits in the "new"
branch but no other branch):
$ git log new $(git for-each-ref --format='%(refname)' 'refs/heads/*'
| grep -v '^refs/heads/new$' | sed -e s/^/^/)
Miklos Vajna· Dec 17, 2009, 00:20 UTC · re: Elijah Newren · lore

Re: How do I show only log messages for commits on a specific branch?

On Wed, Dec 16, 2009 at 04:59:54PM -0700, Elijah Newren <newren@gmail.com> wrote:
Show 12 quoted lines
> Did you try it with a 'new' branch in your repository that started at
> the beginning of history rather than at some commit?  "git log new"
> and "git log new@{30.years.ago}..new" are not the same for me with
> git-1.6.5.5:
> 
> $ git init repo
> $ cd repo
> $ echo content> foo && git add foo && git commit -mone foo
> $ echo more content >> foo && git commit -mtwo foo
> $ git checkout -b new master~1
> $ echo stuff >> foo && git commit -mthree foo
> $ git log new@{30.years.ago}..new
Aah, thanks. Then you can just avoid the warning using
git log $(git reflog show new|sed -n 's/ .*//;$ p')..new
Show 6 quoted lines
> Are you sure?  I'm more inclined to believe he'd like to see all the
> commits that have been added to the "new" branch since he created it
> (which may be the same as what you say, but not necessarily).  Of
> course, neither my assumption or yours match what he actually asked
> for (though I think what he asked for isn't possible and is merely an
> means to the end he really wants).
No, I'm not sure about what he thought, but I hope he will clarify. :)
Stefan Völkel· Dec 17, 2009, 14:20 UTC · re: Miklos Vajna · lore

Re: How do I show only log messages for commits on a specific branch?

Hi,
> git log $(git reflog show new|sed -n 's/ .*//;$ p')..new

I had trouble getting the above to work as a git alias (someething wrt escaping I guess), however this:

        gl = log --graph --pretty=oneline --abbrev-commit
	bl = !sh -c 'git gl $0 --not $(git for-each-ref --format=%\\(refname\\)
refs/heads/* | grep -v refs/heads/$0)'
does exactly what I want:
	# git reflog show new
	76cacd3 new@{0}: commit: B
	9638379 new@{1}: commit: A
	7944f55 new@{2}: branch: Created from HEAD
	# git gl
	* 76cacd3 B
	* 9638379 A
	* 7944f55 Y
	* b8e4a96 X
	# git bl new
	* 76cacd3 B
	* 9638379 A
Thanks for the help,
	Stefan
David Roden· Dec 17, 2009, 09:20 UTC · re: bd@bc-bd.org · lore

Re: How do I show only log messages for commits on a specific branch?

bd@bc-bd.org wrote:
Show 20 quoted lines
> imagine this:
> 
> --A--*--B (new)
> /
> *--X--*--Y (master)
> 
> Now I'd like to list only log messages for A..B (X..B would be okay too).
> 
> I know of
> 
> git log master..new
> 
> however then I need to remember that I branched new of master, and to be
> honest, sometimes I forget.
> 
> So how do I:
> 
> git please-tell-me-the-branch-I-started-this-branch-from new
> 
> Thanks in advance,
I have had wonderful results using
    git log new --not master
or
    git log new ^master

This is using git 1.6.4.4 and this way of specifying commits is not mentioned in the man page—it seems to work, though.

	David
Pat Notz· Dec 17, 2009, 15:04 UTC · re: bd@bc-bd.org · lore

Re: How do I show only log messages for commits on a specific branch?

> So how do I:
>
>        git please-tell-me-the-branch-I-started-this-branch-from new
>

You may also be interested in the git show-branch command. The output may be unintuitive at first but once you grok it it's pretty useful... especially if you have several branches.

Aside from the man page, here's a blog post the describes the output: https://wincent.com/wiki/Understanding_the_output_of_%22git_show-branch%22

~ Pat

← back to recent threads