threads / discuss / 26690

how to list commits on branch since last merge

Subject: how to list commits on branch since last merge

## tl;dr

13 messages between Mar 8, 2011 and Mar 8, 2011.

replies: 12people: 4as markdown or json

Jay Soffian· Mar 8, 2011, 07:24 UTC · lore
Given this history:
o---o---x---o---...    foo
 \       \
  o---o---m---o---...  bar

I want to list the commits on bar newer than merge m (the last merge from foo). merge-base returns x.

I feel like I'm going to face-palm upon reply, but the only way I see to do it is:

  $ git rev-list --ancestry-path $(git merge-base foo bar)..bar

Or by greping the output of rev-list --merges --parents foo..bar looking for the merge base.

I must be missing something obvious, since this feels like it should be a common operation. :-)

j.
Michael J Gruber· Mar 8, 2011, 08:48 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

Jay Soffian venit, vidit, dixit 08.03.2011 08:24:
Show 19 quoted lines
> Given this history:
> 
> o---o---x---o---...    foo
>  \       \
>   o---o---m---o---...  bar
> 
> I want to list the commits on bar newer than merge m (the last merge
> from foo). merge-base returns x.
> 
> I feel like I'm going to face-palm upon reply, but the only way I see
> to do it is:
> 
>   $ git rev-list --ancestry-path $(git merge-base foo bar)..bar
> 
> Or by greping the output of rev-list --merges --parents foo..bar
> looking for the merge base.
> 
> I must be missing something obvious, since this feels like it should
> be a common operation. :-)
Have you tried:
git rev-list --ancestry-path --left-right foo...bar

If the ">" commits are the ones that you want you only have to wait for the "--right-only" option which is cooking in pu. And grep '^>' for now ;)

Michael
Jay Soffian· Mar 8, 2011, 09:35 UTC · re: Michael J Gruber · lore

Re: how to list commits on branch since last merge

On Tue, Mar 8, 2011 at 3:48 AM, Michael J Gruber <git@drmicha.warpmail.net> wrote:

Show 6 quoted lines
> Have you tried:
>
> git rev-list --ancestry-path --left-right foo...bar
>
> If the ">" commits are the ones that you want you only have to wait for
> the "--right-only" option which is cooking in pu. And grep '^>' for now ;)

Ah. The rev-list man page entry on --ancestry-path only talks about using it with '..', so I didn't even try it with the symmetric diff operator ('...').

That said, seems it would be useful to have an easy way to get to the merge which has a merge-base as one of its parents. Maybe even a generic way to find all commits which have a particular parent. I think rev-list --parents | grep is the only way to do that today.

Thanks,
j.
Michael J Gruber· Mar 8, 2011, 09:39 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

Jay Soffian venit, vidit, dixit 08.03.2011 10:35:
Show 12 quoted lines
> On Tue, Mar 8, 2011 at 3:48 AM, Michael J Gruber
> <git@drmicha.warpmail.net> wrote:
>> Have you tried:
>>
>> git rev-list --ancestry-path --left-right foo...bar
>>
>> If the ">" commits are the ones that you want you only have to wait for
>> the "--right-only" option which is cooking in pu. And grep '^>' for now ;)
> 
> Ah. The rev-list man page entry on --ancestry-path only talks about
> using it with '..', so I didn't even try it with the symmetric diff
> operator ('...').

I understood --ancestry-path only after looking at revision.c, where there's talk about "bottom commits", which gave me the right hint (because I've been messing with the walker lately).

Show 5 quoted lines
> 
> That said, seems it would be useful to have an easy way to get to the
> merge which has a merge-base as one of its parents. Maybe even a
> generic way to find all commits which have a particular parent. I
> think rev-list --parents | grep is the only way to do that today.

I had a patch for that but it was shot down because of the "grep" workaround:

http://permalink.gmane.org/gmane.comp.version-control.git/157636
Maybe I should try again...
Michael
Jay Soffian· Mar 8, 2011, 09:43 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

On Tue, Mar 8, 2011 at 4:35 AM, Jay Soffian <jaysoffian@gmail.com> wrote:
Show 12 quoted lines
> On Tue, Mar 8, 2011 at 3:48 AM, Michael J Gruber
> <git@drmicha.warpmail.net> wrote:
>> Have you tried:
>>
>> git rev-list --ancestry-path --left-right foo...bar
>>
>> If the ">" commits are the ones that you want you only have to wait for
>> the "--right-only" option which is cooking in pu. And grep '^>' for now ;)
>
> Ah. The rev-list man page entry on --ancestry-path only talks about
> using it with '..', so I didn't even try it with the symmetric diff
> operator ('...').
And with the clue to use '...', it's easy:
  $ git log --ancestry-path foo...bar ^foo

Still want an easy way for merge-base to report the merge which contains the merge-base. That will wait for another day.

j.
Michael J Gruber· Mar 8, 2011, 09:48 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

Jay Soffian venit, vidit, dixit 08.03.2011 10:43:
Show 20 quoted lines
> On Tue, Mar 8, 2011 at 4:35 AM, Jay Soffian <jaysoffian@gmail.com> wrote:
>> On Tue, Mar 8, 2011 at 3:48 AM, Michael J Gruber
>> <git@drmicha.warpmail.net> wrote:
>>> Have you tried:
>>>
>>> git rev-list --ancestry-path --left-right foo...bar
>>>
>>> If the ">" commits are the ones that you want you only have to wait for
>>> the "--right-only" option which is cooking in pu. And grep '^>' for now ;)
>>
>> Ah. The rev-list man page entry on --ancestry-path only talks about
>> using it with '..', so I didn't even try it with the symmetric diff
>> operator ('...').
> 
> And with the clue to use '...', it's easy:
> 
>   $ git log --ancestry-path foo...bar ^foo
> 
> Still want an easy way for merge-base to report the merge which
> contains the merge-base. That will wait for another day.
You mean shorter than:
git rev-list --merges -1 $(git merge-base foo bar)
Or maybe I'm misunderstanding "contain".
Michael
Jay Soffian· Mar 8, 2011, 10:11 UTC · re: Michael J Gruber · lore

Re: how to list commits on branch since last merge

On Tue, Mar 8, 2011 at 4:48 AM, Michael J Gruber <git@drmicha.warpmail.net> wrote:

Show 5 quoted lines
> You mean shorter than:
>
> git rev-list --merges -1 $(git merge-base foo bar)
>
> Or maybe I'm misunderstanding "contain".
Going back to my original picture, I mean commit m:
  o---o---x---o---...    foo
   \       \
    o---o---m---o---...  bar

merge-base foo bar gives me x; to get m I then need to grep the output of rev-list --parents for x.

j.
Michael J Gruber· Mar 8, 2011, 10:25 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

Jay Soffian venit, vidit, dixit 08.03.2011 11:11:
Show 18 quoted lines
> On Tue, Mar 8, 2011 at 4:48 AM, Michael J Gruber
> <git@drmicha.warpmail.net> wrote:
>> You mean shorter than:
>>
>> git rev-list --merges -1 $(git merge-base foo bar)
>>
>> Or maybe I'm misunderstanding "contain".
> 
> Going back to my original picture, I mean commit m:
> 
>   o---o---x---o---...    foo
>    \       \
>     o---o---m---o---...  bar
> 
> merge-base foo bar gives me x; to get m I then need to grep the output
> of rev-list --parents for x.
> 
> j.
Maybe
git rev-list --ancestry-path --merges $(git merge-base foo bar)..bar
or, with the patch in pu
git rev-list --ancestry-path --merges --right-only foo...bar
each piped into tail -1 ?
Michael
Jeff King· Mar 8, 2011, 17:12 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

On Tue, Mar 08, 2011 at 05:11:16AM -0500, Jay Soffian wrote:
Show 8 quoted lines
> Going back to my original picture, I mean commit m:
> 
>   o---o---x---o---...    foo
>    \       \
>     o---o---m---o---...  bar
> 
> merge-base foo bar gives me x; to get m I then need to grep the output
> of rev-list --parents for x.
Isn't the merge the first commit in bar that is not in foo? IOW:
  git rev-list foo..bar | tail -n 1
?

I admit it's not particularly elegant, though. And I haven't given enough thought to decide whether that happens to work in your case, or if it is more general. :)

-Peff
Jay Soffian· Mar 8, 2011, 17:39 UTC · re: Jeff King · lore

Re: how to list commits on branch since last merge

On Tue, Mar 8, 2011 at 12:12 PM, Jeff King <peff@peff.net> wrote:
Show 12 quoted lines
> On Tue, Mar 08, 2011 at 05:11:16AM -0500, Jay Soffian wrote:
>
>> Going back to my original picture, I mean commit m:
>>
>>   o---o---x---o---...    foo
>>    \       \
>>     o---o---m---o---...  bar
>>
>> merge-base foo bar gives me x; to get m I then need to grep the output
>> of rev-list --parents for x.
>
> Isn't the merge the first commit in bar that is not in foo? IOW:
No, because bar is never merged to foo. Let me relabel the picture:
   o---o---x---o---...    foo
    \       \
     a---b---c---d---...  bar
>  git rev-list foo..bar | tail -n 1

That would return 'a'. merge-base foo bar returns x. I want 'c'. So again, I can do either:

  $ git rev-list foo bar --merges --parents | grep " $(git merge-base foo bar)"
Or:
  $ git rev-list --ancestry-path foo...bar ^foo | tail -n 1

I guess this is not at all a common thing, since it seems to be confounding the list. :-)

My use case is that I maintain a downstream project, so bar never merges back to foo, but sometimes I ask the question "what have we done on bar since we last merged in foo". I think --ancestry-path really is the answer:

  $ git log --reverse --ancestry-path foo...bar ^foo
Is actually quite nice.
j.
Jeff King· Mar 8, 2011, 18:05 UTC · re: Jay Soffian · lore

Re: how to list commits on branch since last merge

On Tue, Mar 08, 2011 at 12:39:10PM -0500, Jay Soffian wrote:
Show 12 quoted lines
> >> Going back to my original picture, I mean commit m:
> >>
> >>   o---o---x---o---...    foo
> >>    \       \
> >>     o---o---m---o---...  bar
> >>
> >> merge-base foo bar gives me x; to get m I then need to grep the output
> >> of rev-list --parents for x.
> >
> > Isn't the merge the first commit in bar that is not in foo? IOW:
> 
> No, because bar is never merged to foo. Let me relabel the picture:
Oh, of course. Sorry for the misdirection. Too little sleep. :)
> I guess this is not at all a common thing, since it seems to be
> confounding the list. :-)

Yeah, I think in many cases when "foo" and "bar" are merged, they both end up getting the merge commit, and "foo..bar" and "foo...bar" becomes a lot more useful.

Yours is more of a long-running maintenance branch scenario. Which is not all that uncommon, of course, but I can't remember a time when I wanted to ask for what you're looking for.

-Peff
Andreas Schwab· Mar 8, 2011, 19:08 UTC · re: Jeff King · lore

Re: how to list commits on branch since last merge

Jeff King <peff@peff.net> writes:
Show 7 quoted lines
> On Tue, Mar 08, 2011 at 05:11:16AM -0500, Jay Soffian wrote:
>
>> Going back to my original picture, I mean commit m:
>> 
>>   o---o---x---o---...    foo
>>    \       \
>>     o---o---m---o---...  bar
      b1
Show 7 quoted lines
>> 
>> merge-base foo bar gives me x; to get m I then need to grep the output
>> of rev-list --parents for x.
>
> Isn't the merge the first commit in bar that is not in foo? IOW:
>
>   git rev-list foo..bar | tail -n 1

That would show the commit marked b1 above, wouldn't it? ^foo cuts only x and its parents, but not the other parent of m.

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Jeff King· Mar 8, 2011, 21:03 UTC · re: Andreas Schwab · lore

Re: how to list commits on branch since last merge

On Tue, Mar 08, 2011 at 08:08:55PM +0100, Andreas Schwab wrote:
Show 6 quoted lines
> > Isn't the merge the first commit in bar that is not in foo? IOW:
> >
> >   git rev-list foo..bar | tail -n 1
> 
> That would show the commit marked b1 above, wouldn't it?  ^foo cuts only
> x and its parents, but not the other parent of m.
Yes, just me being dumb. See the other subthread.
-Peff

← back to recent threads